hdu5890Eighty seven【bitset优化01背包】
来源:互联网 发布:windowsphone同步软件 编辑:程序博客网 时间:2024/05/17 01:04
Eighty seven
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 583 Accepted Submission(s): 208
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 prepareN 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
题意:给你n个数,m次询问,每次询问给你三个数,问在给出的数里面存不存在任意取10个(不包含这三个数)的数的和==87。
做法:利用bitset预处理,bitset是什么玩意?和set一样,都可以看作是集合,只不过里面的值只有0/1,这里面bitset定义为数组,ss[已经用的数字个数][凑出来的和],那么ss[j]|=ss[j-1]<<num[i];的意思就是在添加了第i个数的时候可以在原有的基础上改变。这样到最后就可以判断出[10][87]是否可达。
#include <iostream>#include<cstdio>#include<bitset>#include<algorithm>using namespace std;bitset<90>ss[20];int n,num[100];bool dp[55][55][55];void make(int x,int y,int z){ for(int i=0;i<=11;i++)ss[i].reset(); ss[0][0]=1; for(int i=1;i<=n;i++) { if(i==x||i==y||i==z||num[i]>87)continue; for(int j=10;j>=1;j--) ss[j]|=ss[j-1]<<num[i]; } if(ss[10][87]==1)dp[x][y][z]=1; else dp[x][y][z]=0;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&num[i]); for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) for(int k=j;k<=n;k++) make(i,j,k); int m; scanf("%d",&m); while(m--) { int xx[3]; scanf("%d%d%d",&xx[0],&xx[1],&xx[2]); sort(xx,xx+3); if(dp[xx[0]][xx[1]][xx[2]])puts("Yes"); else puts("No"); } } return 0;}
0 0
- hdu5890Eighty seven【bitset优化01背包】
- hdu5890 Eighty seven(背包+bitset优化)
- hdu5890Eighty seven
- hdu 5890 Eighty seven 背包bitset
- hdu 5890 Eighty seven(背包+bitset)
- HDU 5890 Eighty seven(bitset优化dp)
- hdu 5890 01背包(bitset优化)
- bitset优化背包...
- 【HDU 5890】Eighty seven(bitset+DP+优化)
- hdu5890 bitset优化0/1背包
- 2016 ACM/ICPC Asia Regional Qingdao hdu5890 Eighty seven(DP+bitset优化妙用)
- Eighty seven (bitset优化) 在n个数中取m个数和为k
- HDU 5890 Eighty seven (DP + bitset) 优化 (2016 青岛网络赛)
- HDU 5890 Eighty seven ACM/ICPC 2015 Shenyang Online(DP+bitset优化)
- hdu 6140 Hybrid Crystals 阅读题 OR bitset 优化01背包
- POJ 1742 coins(背包+二进制优化+bitset)
- bitset优化
- hdu 6140 bitset+背包
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- jquery多个文本框添加
- freemarker+docx4j 生产自定义word
- 解决eclipse中NDK部分函数could not be resolved
- 开博客之第一篇
- hdu5890Eighty seven【bitset优化01背包】
- service的用法
- Hive SQL操作与函数自定义(一)
- AsyncTask和Handler的优缺点比较
- Android-优化不同版本系统WebView版本兼容性问题
- Maven入门(含实例教程)
- 驱动工程师/BSP工程师笔试题
- DirectX 的入门总结
- angular2中standalone=“true”和Name attribute must be set if ngModel is used within a form的问题