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 |
为什么用double错误的呢??虽然我的代码是笨了点,每年做一次背包#include <iostream> using namespace std; int dp[100200],w[12],v[12]; int fmax(int a,int b) {return a>b?a:b;} int main() { int t; scanf("%d",&t); while(t--) { int money,year,i,j,bond,k; double sum_money; scanf("%d%d",&money,&year); sum_money=money/1000.0; scanf("%d",&bond); for(i=1;i<=bond;++i) { scanf("%d%d",&w[i],&v[i]); w[i]/=1000; } while(year--) { memset(dp,0,sizeof(dp)); k=(int)sum_money; for(i=1;i<=bond;++i) for(j=w[i];j<=k;++j) dp[j]=fmax(dp[j],dp[j-w[i]]+v[i]); sum_money+=dp[k]/1000.0; } money=(int)(sum_money*1000); printf("%d\n",money); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator