标签:des style blog http color strong
Description
Input
Output
Sample Input
5 -5 7 8 -6 6 -3 2 1 -8 -5
Sample Output
8
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <map> 5 using namespace std; 6 #define ben 110000 7 #define INF -999999999 8 typedef struct abcd 9 { 10 int s,f; 11 }abcd; 12 abcd a[200]; 13 int dp[200000]; 14 int main() 15 { 16 int n,i,j; 17 scanf("%d",&n); 18 for(i=0;i<n;i++) 19 { 20 scanf("%d%d",&a[i].s,&a[i].f); 21 } 22 for(i=0;i<200000;i++)dp[i]=INF; 23 dp[ben]=0; 24 for(i=0;i<n;i++) 25 { 26 if(a[i].s>=0) 27 { 28 for(j=200000-1;j-a[i].s>=0;j--) 29 dp[j]=max(dp[j-a[i].s]+a[i].f,dp[j]); 30 } 31 else 32 { 33 for(j=0;j-a[i].s<200000;j++) 34 dp[j]=max(dp[j-a[i].s]+a[i].f,dp[j]); 35 } 36 } 37 int ans=0; 38 for(i=ben;i<200000;i++) 39 if(dp[i]>=0) 40 ans=max(ans,dp[i]+i-ben); 41 cout<<ans<<endl; 42 }
Cow Exhibition 变种背包,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/ERKE/p/3841691.html