hdu 5616(dp)
来源:互联网 发布:阿尔法脑电波音乐软件 编辑:程序博客网 时间:2024/04/28 06:36
Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 733 Accepted Submission(s): 351
Problem Description
Jim has a balance and N weights. (1≤N≤20)
The balance can only tell whether things on different side are the same weight.
Weights can be put on left side or right side arbitrarily.
Please tell whether the balance can measure an object of weight M.
The balance can only tell whether things on different side are the same weight.
Weights can be put on left side or right side arbitrarily.
Please tell whether the balance can measure an object of weight M.
Input
The first line is a integer T(1≤T≤5) , means T test cases.
For each test case :
The first line isN , means the number of weights.
The second line areN number, i'th number wi(1≤wi≤100) means the i'th weight's weight is wi .
The third line is a numberM . M is the weight of the object being measured.
For each test case :
The first line is
The second line are
The third line is a number
Output
You should output the "YES"or"NO".
Sample Input
121 43245
Sample Output
NOYESYESHintFor the Case 1:Put the 4 weight aloneFor the Case 2:Put the 4 weight and 1 weight on both side
Source
BestCoder Round #70
//好久没刷题了。。这题求的是给你N个数是否可以通过加减运算得到另外一个数
//主要利用类01背包的思想 dp[i][k] 为前i个数是否可以得到k 可以得到为1不能得到为0
//dp[i][k] = max(dp[i-1][k],dp[i-1][abs(k-a[i])]); dp[i][k] =max(dp[i][k],dp[i-1][k+a[i]])
#include <bits/stdc++.h>using namespace std;const int N=25;int arr[N];int dp[N][N*100];int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0;i<=n;i++) for(int k=0;k<N*100;k++) dp[i][k]=0; for(int i=1;i<=n;i++) { scanf("%d",arr+i); dp[i][0]=1; } dp[0][0]=1; for(int i=1;i<=n;i++) { for(int k=1;k<n*100;k++) { dp[i][k]=max(dp[i-1][k],dp[i-1][abs(k-arr[i])]); dp[i][k]=max(dp[i][k],dp[i-1][k+arr[i]]); } } int m; scanf("%d",&m); while(m--) { int val; scanf("%d",&val); if(dp[n][val]) puts("YES"); else puts("NO"); } } return 0;}
0 0
- hdu 5616(dp)
- HDU DP
- DP? HDU
- DP? HDU
- DP? HDU
- 【dp】HDU
- 【dp】HDU
- 【dp】 HDU
- DP? HDU
- HDU 5616 Jam's balance(dp)
- hdu 5616 Jam's balance(简单dp)
- HDU 5616 Jam's balance(dp)
- HDU 5616 Jam's balance dp, bitset
- HDU 1003 && HDU 1231 DP
- hdu 1058 DP
- HDU 1069 dp
- HDU 1024(DP)
- hdu 1257 dp+贪心
- PHP输出gzip压缩
- CSU 1515 Sequence(莫队算法)
- [BZOJ4381][POI2015]Odwiedziny (树链刨分/倍增)
- 移动前端开发之viewport的深入理解
- TabHost选项卡的 功能和用法
- hdu 5616(dp)
- vector容器的自增长
- 面试题总结
- bc19&&hdoj5108&&hdoj5109
- 堆排序
- Web 开发常见安全问题
- Android中相机调用及将照片存储sd 实例,转自:http://android.tgbus.com/Android/tutorial/201204/419574.shtml
- iOS小知识点
- 打开项目资源内的图片,并作为默认打开图片的应用