hdu 5890(01背包+ bitset 优化)

Eighty seven

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 1605    Accepted Submission(s): 515


 

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 Ncards 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 integer N(N≤50).
The second line contains N 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.

 

 

Output

For each turn of each case, output 'Yes' if there exists at least one solution, otherwise output 'No'.

 

 

Sample Input

 

1 12 1 2 3 4 5 6 7 8 9 42 21 22 10 1 2 3 3 4 5 2 3 2 10 10 10 10 11 11 10 1 1 1 2 10 1 11 12 1 10 10 11 11 12

 

 

Sample Output

 

No No No Yes No Yes No No Yes Yes

 

 

Source

2016 ACM/ICPC Asia Regional Qingdao Online

 

 

Recommend

wange2014   |   We have carefully selected several similar problems for you:  6379 6378 6377 6376 6375 

 

题意: 现在给你n个数,每次查询问从点集中删去 x,y,z 三个数,你要从其他的剩下的数中能否找出10个数使得十个数相加为87?

思路: 背包来做,由于n 比较小,所以我可以预先处理出所有的情况,然后用bitset 搞一搞。

另附一句  bitset 真的强。 

推荐题集: 大神大神

代码:

#include

using namespace std;
const int N =55;
int a[N];
int flag[N][N][N];
int n;
bitset<100>dp[12];

int jud(int aa,int b,int c)
{
    for(int i=1;i<=11;i++) dp[i].reset();
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=9;j>=0;j--){
            if(i==aa) continue;
            if(i==b) continue;
            if(i==c) continue;
            dp[j+1]|=(dp[j]<

 

你可能感兴趣的:(背包,dp)