hdu 5890 Eighty seven
来源:互联网 发布:捷克电视网络运营商 编辑:程序博客网 时间:2024/05/24 05:00
Eighty seven
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 243 Accepted Submission(s): 74
Problem Description
Mr. Fib is a mathematics teacher of a primary school. In the next lesson, he is planning to teach children how to add numbers up. Before the class, he will prepare N cards with numbers. The number on the i -th card is ai . In class, each turn he will remove no more than 3 cards and let students choose any ten cards, the sum of the numbers on which is 87 . After each turn the removed cards will be put back to their position. Now, he wants to know if there is at least one solution of each turn. Can you help him?
Input
The first line of input contains an integer t (t≤5) , the number of test cases. t test cases follow.
For each test case, the first line consists an integerN(N≤50) .
The second line containsN non-negative integers a1,a2,...,aN . The i -th number represents the number on the i -th card. The third line consists an integer Q(Q≤100000) . Each line of the next Q lines contains three integers i,j,k , representing Mr.Fib will remove the i -th, j -th, and k -th cards in this turn. A question may degenerate while i=j , i=k or j=k .
For each test case, the first line consists an integer
The second line contains
Output
For each turn of each case, output 'Yes' if there exists at least one solution, otherwise output 'No'.
Sample Input
1121 2 3 4 5 6 7 8 9 42 21 22101 2 33 4 52 3 210 10 1010 11 1110 1 11 2 101 11 121 10 1011 11 12
Sample Output
NoNoNoYesNoYesNoNoYesYes
Source
2016 ACM/ICPC Asia Regional Qingdao Online
Recommend
wange2014 | We have carefully selected several similar problems for you: 5891 5889 5887 5886 5885
题意:给你n个数,m次询问,每次询问给你三个数,问在给出的数里面存不存在任意取10个(不包含这三个数)的数的和==87。思路:用bitset暴力dp,时间卡着过,暴力打表用dp[i][j][k]表示存不存在,然后就是用bitset优化0 1背包。剩下的看代码:
#include<set>#include<map>#include<ctime>#include<cmath>#include<stack>#include<queue>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<bitset>#include<functional>typedef long long LL;using namespace std;#define inf 0x3f3f3f3f#define maxn 55typedef long long LL;int a[maxn], dp[maxn][maxn][maxn];bitset<90>s[11];int n;bool solve(int x, int y, int z){for (int i = 0; i<11; i++)s[i].reset();s[0][0] = 1;for (int i = 1; i <= n; i++){if (i == x || i == y || i == z || a[i]>87)continue;for (int j = 10; j>0; j--){s[j] |= s[j - 1] << a[i];}}if (s[10][87])return 1;elsereturn 0;}int main(){int t;scanf("%d", &t);while (t--){scanf("%d", &n);for (int i = 1; i <= n; i++){scanf("%d", &a[i]);}for (int i = 1; i <= n; i++){for (int j = i; j <= n; j++){for (int k = j; k <= n; k++){dp[i][j][k] = solve(i, j, k);}}}int q;scanf("%d", &q);while (q--){int b[3];scanf("%d%d%d", &b[0], &b[1], &b[2]);sort(b, b + 3);if (dp[b[0]][b[1]][b[2]])printf("Yes\n");elseprintf("No\n");}}}
0 0
- hdu 5890 Eighty seven
- Hdu 5890 Eighty seven
- Hdu 5890 Eighty seven
- hdu 5890 Eighty seven DP
- hdu 5890 Eighty seven 背包bitset
- HDU 5890 Eighty seven(bitset优化dp)
- hdu 5890 Eighty seven(背包+bitset)
- 【HDU 5890】Eighty seven(bitset+DP+优化)
- Eighty seven
- HDU 5890 Eighty seven (DP + bitset) 优化 (2016 青岛网络赛)
- HDU 5890 Eighty seven ACM/ICPC 2015 Shenyang Online(DP+bitset优化)
- hdu5890 Eighty seven(DP)
- HDU5890 Eighty seven (数位DP)
- hdu5890 Eighty seven(背包+bitset优化)
- 1783 转化为one thousand and seven hundred and eighty -three
- 2016 ACM/ICPC Asia Regional Qingdao hdu5890 Eighty seven(DP+bitset优化妙用)
- Eighty seven (bitset优化) 在n个数中取m个数和为k
- HDU The Seven Percent Solution
- Qt入门——三个臭皮匠顶个诸葛亮
- 62. mybatis 使用PageHelper不生效
- 第五十九篇:main.c:62:9: note: use option -std=c99 or -std=gnu99 to compile your code
- Oracle学习总结(二)
- 63. JPA/Hibernate/Spring Data概念
- hdu 5890 Eighty seven
- Swift 3.0 Released! 展望swift 4
- Hadoop(06) RPC
- 64. JPA命名策略
- 第三周项目4-顺序表应用 删除【x,z】之间的元素
- 第三周项目2—建设“顺序表”算法库
- 在内、外部存储中读写数据
- C++ (一)
- 利用AngularJS中ng-include实现静态HTML头文件和尾文件导入