hdu5616 Jam's balance
来源:互联网 发布:淘宝解冻的金额在哪 编辑:程序博客网 时间:2024/05/18 02:21
Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 386 Accepted Submission(s): 182
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
直接暴力枚举所有可能的值,然后查表就好了
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int rec[25],dp[25][2005];int main(){ int T, n, m, sum; scanf("%d", &T); while (T--) { sum = 0; scanf("%d", &n); memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { scanf("%d", &rec[i]); sum += rec[i]; dp[i][0] = 1; } dp[0][rec[0]] = 1; for (int i = 1; i < n; i++) { for (int j = 1; j <= sum; j++) { dp[i][j] |= dp[i - 1][j]; dp[i][j + rec[i]] |= dp[i - 1][j]; dp[i][abs(j - rec[i])] |= dp[i - 1][j]; } } scanf("%d", &m); while (m--) { int weight; scanf("%d", &weight); if (dp[n - 1][weight]) puts("YES"); else puts("NO"); } } return 0;}
1 0
- hdu5616 Jam's balance
- HDU5616 Jam's balance
- HDU5616 Jam's balance 动态规划
- 母函数解决 Jam's balance hdu5616
- HDU5616 Jam's balance[背包dp变形]
- hdu5616 Jam's math problem
- Jam's balance
- HDU 5616 Jam's balance
- hdu 5616 Jam's balance
- HDU 5616 Jam's balance
- HDU 5616 Jam's balance
- hdoj-5616-Jam's balance
- HDU 5616Jam's balance
- HDU 5616 Jam's balance
- HDOJ 5616 Jam's balance(母函数)
- hdoj 5616 Jam's balance 【母函数】
- HDOJ 5616-Jam's balance【模拟】
- HDOJ 5616 Jam's balance (暴力)
- SYN标志
- [java]_[Collections.sort()实现List排序]
- JAF框架及在JavaMail中的应用
- 快速幂算法代码
- KMP快速字符串匹配 (next数组优化)
- hdu5616 Jam's balance
- 17228 真.狼人游戏
- iOS字体不清晰问题
- iOS开发学习之Quartz2D绘图
- 【Leetcode】Validate Binary Search Tree
- 生活随笔:病人(2)
- 《Android开发艺术探索》读书笔记 (2) 第2章 IPC机制
- Codeforces 621 D Rat Kwesh and Cheese
- [android]_[handler的简单使用]