标签:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int inf = 0x3f3f3f3f; const int MAX = 100000+5; int dp[2*MAX]; int a[105],b[105]; int main() { int x,y; int T; while(~scanf("%d",&T)){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i = 1 ; i <= T; i++){ scanf("%d%d",&a[i],&b[i]); } for(int i = 0; i <= 200000;i++) dp[i] = -inf; dp[100000] = 0; for(int i = 1; i <= T; i++){ if(a[i] < 0 && b[i] < 0) continue; else if(a[i] > 0){ for(int j = 200000; j >= a[i]; j--){ if(dp[j-a[i]] > - inf){ dp[j] = max(dp[j],dp[j-a[i]] + b[i]); } } } else { for(int j = a[i]; j <= 200000+a[i]; j++){ if(dp[j-a[i]] > -inf){ dp[j] = max(dp[j],dp[j-a[i]]+b[i]); } } } } int max1 = -inf; for(int i = 100000; i <= 200000; i++){ if(dp[i] >= 0) max1 = max(max1,dp[i]+i-100000); } printf("%d\n",max1); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4447966.html