Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
hawk大大,请帮我看一下吧,submit到吐血了,改到几乎和AC的一模一样了,谢谢!In Reply To:dp方程是不是:f[i][j] = min{f[i-1][k]+(j+sta[i]-station[i-1]-k)*price[i-1])},对k枚举?另外,这题是单case么? Posted by:sunmoonstar_love at 2005-07-10 19:47:39 //#include <stdio.h> #include<iostream> //#include<fstream> using namespace std; int f[102][201],i,j,k,d,dis[102],sta[102],pri[102],n,inf = 1000000000,tmp; int main() { // freopen("in.txt","r",stdin); // freopen("out2.txt","w",stdout); // scanf("%d",&d); // ifstream cin("in.txt"); // ofstream cout("out2.txt"); cin>>d; n = 1; while(cin>>sta[n]>>pri[n]) n++; sta[n] = d; sta[0] = 0; for(i=1; i<=n; i++) { dis[i]=sta[i]-sta[i-1]; if(dis[i]>200 || (i==1||i==n)&&dis[i]>100) { cout<<"Impossible"<<endl; return 0; } for(j=0; j<=200; j++) { f[i][j] = inf; } } f[1][100-sta[1]] = 0; for(i=1; i<n; i++) { for(j=0; j<=200; j++) { if(f[i][j]!=inf) { for(k=0; k<=200-j; k++) { if(j+k>=dis[i+1] && f[i][j]+k*pri[i]<f[i+1][j+k-dis[i+1]]) { f[i+1][j+k-dis[i+1]] = f[i][j]+k*pri[i]; } } } } } cout<<f[n][100]<<endl; // printf("%d\n",f[n][100]); // cin.close(); // cout.close(); // fclose(stdin); // fclose(stdout); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator