HDU 5890 Eighty seven violence +bitset optimized backpack

Source: Internet
Author: User

Eighty Seven

Time limit:3000/1000 MS (java/others) Memory limit:102400/102400 K (java/others)


Problem descriptionmr. Fib is a mathematics teacher of a primary school. In the next lesson, he's planning to teach children how to add numbers up. Before the class, he'll prepareNCards with numbers. The number on theI-th Card isai . In class, each turn he'll remove no more than 3 cards and let students choose a ten cards, the sum of the numbers on which is . After each turn the removed cards is put back to their position. Now, he wants to know if there are at least one solution for each turn. Can you help him?

Inputthe first line of input contains an integerT (t≤5) , the number of test cases.TTest cases follow.
For each test case, the first line consists an integern(n≤) .
The second line containsNnon-negative integersa1,a2,.. . ,aN . TheI-th number represents the number on theI-th card. The third line consists an integerq(q≤100000) . Each line of the nextQLines contains three integersi,J,K , representing Mr.fib would remove theI-th,J-th, andk-th cards in this turn. A question may degenerate while I=J, i=k or j=k .

Outputfor each turn of all case, output ' Yes ' If there exists at least one solution, otherwise output ' No '.

Sample Input1121 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 Outputnononoyesnoyesnonoyesyes

Source2016 ACM/ICPC Asia Regional Qingdao Online

Bitset optimize 87*n to 10*n;

#include <bits/stdc++.h>using namespacestd;#definell Long Long#definePi (4*atan (1.0))Const intn=1e5+Ten, m=1e6+Ten, inf=1e9+Ten, mod=1e9+7;Constll inf=1e18+Ten; Bitset< ->dp[ One];intans[ -][ -][ -];inta[ -],n,m;intq[5];intCheckintXintYintz) {     for(intI=0; i<=n;i++) Dp[i].reset (); dp[0][0]=1;  for(intI=1; i<=n;i++)    {        if(i!=x&&i!=y&&i!=z) for(intt=Ten; t>=1; t--) Dp[t]|=dp[t-1]<<A[i]; }    if(dp[Ten][ the]==1)        return 1; return 0;}intMain () {intT; scanf ("%d",&T);  while(t--) {memset (ans,0,sizeof(ans)); scanf ("%d",&N);  for(intI=1; i<=n;i++) scanf ("%d",&A[i]);  for(intI=1; i<=n;i++)             for(intj=i;j<=n;j++)                 for(intk=j;k<=n;k++)                if(check (i,j,k)) ans[i][j][k]=1; scanf ("%d",&m);  while(m--)        {             for(intI=0;i<3; i++) scanf ("%d",&Q[i]); Sort (Q,q+3); if(ans[q[0]][q[1]][q[2]]) printf ("yes\n"); Elseprintf ("no\n"); }    }    return 0;}

HDU 5890 Eighty seven violence +bitset optimized backpack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.