Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

看了黑书上给的一个方程,稍微想了一下,就出来了……

Posted by xijunlee93 at 2013-04-05 11:21:42 on Problem 1260
但是要注意INF的大小啊,要尽量大,不然错的很冤枉
#include<fstream>
#define INF 214000000
using namespace std;

long f[200],a[200],p[200];
long w(int i,int j)
{
    if (i>j)
    return 0;
    int ii,ans=10;
    for (ii=i;ii<=j;ii++)
      ans+=a[ii];
    ans*=p[j];
    return ans;
}
long min(long a,long b)
{
    if (a<b)
    return a;
    else return b;
}
int main()
{
    ifstream infile;
    ofstream outfile;
    infile.open("data.in",ios::in);
    outfile.open("data.out",ios::out);
    int t,c,i,j,k=0,temp;
    infile>>t;
    while(k<t)
    {
       infile>>c;
       memset(f,0,sizeof(f));
       memset(a,0,sizeof(a));
       memset(p,0,sizeof(p));
       for (i=1;i<=c;i++)
       infile>>a[i]>>p[i];
       for (i=1;i<=c;i++)
       { 
        temp=INF;
        for (j=0;j<i;j++)
        temp=min(temp,f[j]+w(j+1,i));
        f[i]=temp;
       }
       outfile<<f[c]<<endl;
       k++;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator