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 |
求解,求回答为什么zero要10000才行?1005为什么不行? #include <iostream> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <algorithm> using namespace std; #define inf (0x3f3f3f3f) const int max_a=105; const int max_b=200100; const int zero=10050; int dp[max_b]; int main() { int ans,i,j; int t; int a[max_a],b[max_b]; while(~scanf("%d",&t)) { for(i=1;i<=t;i++) { scanf("%d %d",&a[i],&b[i]); } memset(dp,-inf,sizeof(dp)); dp[zero]=0; for(i=t;i>0;i--) { if(a[i]>0) { for(j=max_b-1;j>=a[i];j--) dp[j]=max(dp[j-a[i]]+b[i],dp[j]); } else { for(j=0;j<max_b+a[i];j++) dp[j]=max(dp[j-a[i]]+b[i],dp[j]); } } ans=0; for(i=zero;i<max_b;i++) { if(dp[i]>0 && (i-zero+dp[i]>ans)) ans=i-zero+dp[i]; } printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator