ZOJ1880 POJ2576 Tug of War,DP
2012-08-03 20:41
363 查看
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=880
http://poj.org/problem?id=2576
没有什么难度的DP
dp[x][y]表示的是对于用x个人能否到达重量y
注意只有一个人的情况,为此WA了两次
http://poj.org/problem?id=2576
没有什么难度的DP
dp[x][y]表示的是对于用x个人能否到达重量y
注意只有一个人的情况,为此WA了两次
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-08-03 20:16 # Filename: ZOJ1880 POJ2576 Tug of War.cpp # Description : ******************************************************************************/ #ifdef _MSC_VER #define DEBUG #define _CRT_SECURE_NO_DEPRECATE #endif #include <fstream> #include <stdio.h> #include <iostream> #include <string.h> #include <string> #include <limits.h> #include <algorithm> #include <math.h> #include <numeric> #include <functional> #include <ctype.h> using namespace std; const int kMAX=55; bool dp[kMAX*2][kMAX*450];//dp[x][y]???x?????????y? int value[2*kMAX]; int main(void) { #ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif int n,ncase=1; while(~scanf("%d",&n) && n) { int total=0; memset(dp,false,sizeof(dp)); for(int i=0;i<n;++i) { scanf("%d",&value[i]); total+=value[i]; } int half=total>>1,idx=(n+1)/2; for(int i=0;i<=idx;++i)dp[i][0]=true; for(int i=0;i<n;++i) { for(int j=0;j<idx;++j) { for(int k=0;k+value[i]<=half;++k) if(dp[j][k] && !dp[j+1][k+value[i]]) dp[j+1][k+value[i]]=true; } } int ans=half; while(!dp[idx][ans]) --ans; int tmp=total-ans; if(ans>tmp) swap(ans,tmp); printf("%d %d\n",ans,tmp); } return 0; }
相关文章推荐
- zoj 1880 - Tug of War
- zoj 1880 - Tug of War
- ZOJ 1880 Tug of War
- ZOJ - 1880 Tug of War
- ZOJ_Tug of War DP
- POJ 2576 / Light OJ 1147 Tug of War 状态压缩DP
- POJ2576 Tug of War (二维的01背包)
- poj2576 tug of war
- poj2576 Tug of War(二维费用背包)
- Light oj 1147 - Tug of War(状压dp)
- poj2576-Tug of War(二维背包)
- 动态规划:POJ2576-Tug of War(二维费用的背包问题)
- ZOJ 2852 Deck of Cards(DP)
- Tug of War(严格限制数量的二维费用背包)
- ZOJ 3201 Tree of Tree(树形背包DP)
- UVa 10032 - Tug of War
- sdut 3251 Nias and Tug-of-War 模拟
- ZOJ-1232 Adventure of Super Mario floyd+DP
- ZOJ 3872 Beauty of Array(DP)
- ZOJ 2852 Deck of Cards DP