标签:
#include <cstdio> #include <iostream> #include <string> #include <cstring> #include <algorithm> #include <cmath> #include <vector> #define PI acos(-1.0) #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) #define msd memset(dp,0,sizeof(dp)) using namespace std; //#define LOCAL int dp[300000]; int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); //freopen("out.txt","w",stdout); #endif // LOCAL ios::sync_with_stdio(false); int n; while(cin>>n&&n>0) { int sum=0; vector<int>v; v.clear(); for(int i=0;i<n;i++) { int t1,t2; cin>>t1>>t2; while(t2) {v.push_back(t1);t2--;sum+=t1;} } int m=sum/2; msd,n=v.size(); for(int i=0;i<n;i++) { for(int j=m;j>=v[i];j--) { dp[j]=max(dp[j],dp[j-v[i]]+v[i]); } } printf("%d %d\n",sum-dp[m],dp[m]); } return 0; }
HUD 1171 Big Event in HDU(01背包)
标签:
原文地址:http://www.cnblogs.com/gpsx/p/5207176.html