标签:des style color os io strong for ar art
Description
Input
Output
Sample Input
2 10 1 20 1 3 10 1 20 2 30 1 -1
Sample Output
20 10 40 40
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct node{ int v , m ; } q[100]; int dp[260000] ; int main() { int n , ans , i , j , k , sum , s , l; while(scanf("%d", &n) && n > 0) { ans = 0 ; for(i = 0 ; i < n ; i++) { scanf("%d %d", &q[i].v, &q[i].m); ans += q[i].v*q[i].m ; } sum = ans ; ans = ans / 2 ; memset(dp,0,sizeof(dp)); dp[0] = 1 ; for(i = 0 ; i < n ; i++) { k = -1 ; while( (1<<(k+1)) -1 < q[i].m ) k++ ; for(j = 0 ; j <= k ; j++) { if(j == k) s = q[i].m - (1<<j) + 1 ; else s = 1<<j ; for(l = ans ; l >= s*q[i].v ; l--) if( !dp[l] && dp[ l-s*q[i].v ] ) dp[l] = 1 ; } } for(i = ans ; i >= 0 ; i--) { if( dp[i] ) { printf("%d %d\n", sum-i, i); break; } } } return 0; }
hdu1171--C - Big Event in HDU(多重背包+二进制优化)
标签:des style color os io strong for ar art
原文地址:http://blog.csdn.net/winddreams/article/details/38892991