hdu-5000 Clone(dp)
2016-04-19 11:59
399 查看
题目链接:
Memory Limit: 65536/65536 K (Java/Others)
[align=left]Problem Description[/align]
[align=left] [/align]
After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as he wanted. For example, some of the cloned objects were tall, while some were short; some of them were fat, and some were thin.
More evidence showed that for two clones A and B, if A was no worse than B in all fields, then B could not survive. More specifically, DRD used a vector v to represent each of his clones. The vector v has n dimensions, representing a clone having N abilities. For the i-th dimension, v[i] is an integer between 0 and T[i], where 0 is the worst and T[i] is the best. For two clones A and B, whose corresponding vectors were p and q, if for 1 <= i <= N, p[i] >= q[i], then B could not survive.
Now, as DRD's friend, ATM wants to know how many clones can survive at most.
[align=left]Input[/align]
[align=left] [/align]
The first line contains an integer T, denoting the number of the test cases.
For each test case: The first line contains 1 integer N, 1 <= N <= 2000. The second line contains N integers indicating T[1], T[2], ..., T
. It guarantees that the sum of T[i] in each test case is no more than 2000 and 1 <= T[i].
[align=left]Output[/align]
[align=left] [/align]
For each test case, output an integer representing the answer MOD 10^9 + 7.
[align=left]Sample Input[/align]
[align=left] [/align]
2
1
5
2
8 6
[align=left]Sample Output[/align]
[align=left] [/align]
1
7
题意:
思路:
dp[i][j]表示前j个人和为i的方案数;
dp[i+k][j]=∑dp[i][j-1](0<=k<=a[j]);
结果为dp[sum/2]
,真是谜一样的答案;
sum=∑t[i];
AC代码:
Clone
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)
[align=left]Problem Description[/align]
[align=left] [/align]
After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as he wanted. For example, some of the cloned objects were tall, while some were short; some of them were fat, and some were thin.
More evidence showed that for two clones A and B, if A was no worse than B in all fields, then B could not survive. More specifically, DRD used a vector v to represent each of his clones. The vector v has n dimensions, representing a clone having N abilities. For the i-th dimension, v[i] is an integer between 0 and T[i], where 0 is the worst and T[i] is the best. For two clones A and B, whose corresponding vectors were p and q, if for 1 <= i <= N, p[i] >= q[i], then B could not survive.
Now, as DRD's friend, ATM wants to know how many clones can survive at most.
[align=left]Input[/align]
[align=left] [/align]
The first line contains an integer T, denoting the number of the test cases.
For each test case: The first line contains 1 integer N, 1 <= N <= 2000. The second line contains N integers indicating T[1], T[2], ..., T
. It guarantees that the sum of T[i] in each test case is no more than 2000 and 1 <= T[i].
[align=left]Output[/align]
[align=left] [/align]
For each test case, output an integer representing the answer MOD 10^9 + 7.
[align=left]Sample Input[/align]
[align=left] [/align]
2
1
5
2
8 6
[align=left]Sample Output[/align]
[align=left] [/align]
1
7
题意:
思路:
dp[i][j]表示前j个人和为i的方案数;
dp[i+k][j]=∑dp[i][j-1](0<=k<=a[j]);
结果为dp[sum/2]
,真是谜一样的答案;
sum=∑t[i];
AC代码:
#include <bits/stdc++.h> using namespace std; const int N=1e6+5; typedef long long ll; const ll mod=1e9+7; int t,n,a[2005]; ll dp[4005][2003]; int main() { scanf("%d",&t); while(t--) { int sum=0,ans=0; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); ans+=a[i]; } memset(dp,0,sizeof(dp)); for(int i=0;i<=a[1];i++) { dp[i][1]=1; } for(int i=1;i<=n;i++) { sum+=a[i]; for(int j=0;j<=a[i];j++) { for(int k=0;k<=sum;k++) { dp[k+j][i]+=dp[k][i-1]%mod; dp[k+j][i]%=mod; } } } printf("%lld\n",dp[ans/2] ); } return 0; }
相关文章推荐
- ThinkPHP中order()使用方法详解
- Enjoy $10 cash coupon AF10 for cheapest runescape 2007 gold buying on Rsorder 4.18-4.26
- Ubuntu 14.04 安装配置 JDK8
- jquery事件委托
- ZOJ 3326(E)模拟
- Ubuntu Broadcom无线网卡驱动安装
- Socket类的用法
- 库索引
- LeetCode 155. Min Stack
- ios6新特性之下拉刷新UIRefreshControl
- ORACLE FOR UPDATE与FOR UPDATE OF区别
- Socket类的用法
- invalid constant type: 18
- 使用连接(JOIN)来代替子查询(Sub-Queries) mysql优化系列记录
- 1、php文件上传保存。。。
- JavaWeb 项目——起点新闻社区
- 删除无用的系统服务项
- Linux中的编码转换程序convmv的安装和使用教程
- MySQL中字符串索引对update的影响分析
- vb作业