题目1453:Greedy Tino
来源:互联网 发布:gps时间同步软件 编辑:程序博客网 时间:2024/05/17 09:03
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int t,T,n,wight[101],TotolWight;int GetMax(int a,int b){ return a>b?a:b; }int GetAbs(int x){ return x<0?-x:x; }int DP(){ int i,j,a[2][2001],k=0; memset(a,-1,sizeof(a)); a[0][0]=0; for (i=1;i<=n;i++) { k=1-k; for (j=0;j<=TotolWight;j++) a[k][j]=a[1-k][j]; for (j=0;j<=TotolWight-wight[i];j++) if (a[1-k][j]>=0) a[k][j+wight[i]]=GetMax(a[k][j+wight[i]],a[1-k][j]+wight[i]); for (j=0;j<=TotolWight;j++) if (a[1-k][j]>=0) a[k][GetAbs(j-wight[i])]=GetMax(a[k][GetAbs(j-wight[i])],a[1-k][j]+wight[i]); } if ( !a[k][0] && wight[1] ) return -1; return a[k][0]/2;}int main(){ scanf("%d",&T); for (t=1;t<=T;t++) { scanf("%d",&n); TotolWight=0; for (int i=1;i<=n;i++) { scanf("%d",&wight[i]); TotolWight+=wight[i]; } sort(wight+1,wight+1+n); printf("Case %d: %d\n",t,DP()); } return 0; }
0 0
- 题目1453:Greedy Tino
- 九度 题目1453:Greedy Tino
- 九度1453:Greedy Tino
- 九度OJ 1453 Greedy Tino
- DP练习,九度1453Greedy Tino
- G Greedy Tino
- Training@USC Greedy Tino
- Greedy Tino--undo
- Greedy Tino-动态规划
- 九度OJ 1453 Greedy Tino -- 动态规划
- HDU 3578 Greedy Tino(双塔DP)
- tino 环境
- Greedy
- Greedy
- Greedy
- LeetCode上Tag为贪心算法(Greedy)的题目整理
- 4221 Greedy?
- Greedy Change
- mysql插入太多数据导致MySQL server has gone away
- session cookie token 区别
- ASP .NET MVC LINQ
- 【Java Utility】Jsoup网页爬虫工具--解析HTML语句片段【四】
- D3D中镜子效果的实现
- 题目1453:Greedy Tino
- [RK3288][Android6.0] 调试笔记 --- 修改默认system/bin/下可执行程序权限
- 国科烟雨情
- 文章标题
- leetcode 557. Reverse Words in a String III
- Boost官网地址
- Android okHttp上传单张或多张照片
- webView跳转网站集合
- 深入理解JavaScript 模块模式