Eighty seven

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)

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

bitset把87*n优化成10*n;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
bitset<>dp[];
int ans[][][];
int a[],n,m;
int q[];
int check(int x,int y,int z)
{
for(int i=;i<=n;i++)dp[i].reset();
dp[][]=;
for(int i=;i<=n;i++)
{
if(i!=x&&i!=y&&i!=z)
for(int t=;t>=;t--)
dp[t]|=dp[t-]<<a[i];
}
if(dp[][]==)
return ;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(ans,,sizeof(ans));
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
for(int j=i;j<=n;j++)
for(int k=j;k<=n;k++)
if(check(i,j,k))ans[i][j][k]=;
scanf("%d",&m);
while(m--)
{
for(int i=;i<;i++)
scanf("%d",&q[i]);
sort(q,q+);
if(ans[q[]][q[]][q[]])
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}

hdu 5890 Eighty seven 暴力+bitset优化背包的更多相关文章

  1. HDU5890:Eighty seven(Bitset优化背包)

    Mr. Fib is a mathematics teacher of a primary school. In the next lesson, he is planning to teach ch ...

  2. 洛谷 P5527 - [Ynoi2012] NOIP2016 人生巅峰(抽屉原理+bitset 优化背包)

    洛谷题面传送门 一道挺有意思的题,想到了某一步就很简单,想不到就很毒瘤( 首先看到这样的设问我们显然可以想到背包,具体来说题目等价于对于每个满足 \(i\in[l,r]\) 的 \(a_i\) 赋上一 ...

  3. HDU - 6268: Master of Subgraph (分治+bitset优化背包)

    题意:T组样例,给次给出一个N节点的点权树,以及M,问连通块的点权和sum的情况,输出sum=1到M,用0或者1表示. 思路:背包,N^2,由于是无向的连通块,所以可以用分治优化到NlgN. 然后背包 ...

  4. HDU 5890 Eighty seven

    预处理,$01$背包,$bitset$优化. 可以预处理出每一种询问的答案,用$01$背包计算答案,$dp[i][j][k]$表示,前$i$个数字中,选择了$j$个,能否凑出$k$这个数字,可以开成$ ...

  5. HDU 5890 Eighty seven(DP+bitset优化)

    题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using nam ...

  6. HDU 5313 bitset优化背包

    题目大意: 添加尽可能少的边,最后使图形成二分图 一开始将图区分成一个个联通分量,根据二分图染色,计算出每个联通分量的黑色点和白色点的个数 希望添加的边最少,那么合并的时候,希望黑白块尽可能平均,这无 ...

  7. bitset优化背包

    题目:https://agc020.contest.atcoder.jp/tasks/agc020_c 回忆下一题,是零一背包,主要的做法就是凑出最接近sum/2的价值,然后发现现在的背包的容量是20 ...

  8. AtCoder3857:Median Sum (Bitset优化背包&&对称性求中位数)

    Median Sum You are given N integers A1, A2, ..., AN. Consider the sums of all non-empty subsequences ...

  9. HDU 4920 Matrix multiplication(bitset优化)

    题目链接 Matrix multiplication 求矩阵A和B相乘的结果. 因为答案只要对3取模,所以我们可以通过一些方法来加速计算. 我们对两个矩阵各开两个bitset,分别存储模3余1和模3余 ...

随机推荐

  1. Apple 企业开发者账号申请记录

    1.账号分类 Apple开发者账号分三种,个人,公司,还有企业.个人和公司都称为标准账号. 还有一种是教育机构的账号. 记录:申请日期2013年4月26,看申请周期多长. 个人和公司的就不说了,现在只 ...

  2. ACM至大二省赛小结

    大一进acm坑的,大一上就学了个c,下才学c++,不过 c 学完后学 c++ 感觉很简单,应该是大一下开学左右才开始刷题的,前面都在水???然后因为acm协会有各种月赛校赛什么的,班主任的提醒较多,所 ...

  3. H - N皇后问题

    H - N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descripti ...

  4. Spring整合Velocity模版引擎

    1. 首先通过pom.xml自动加载velocity扩展包到工程: <dependency> <groupId>velocity</groupId> <art ...

  5. js特殊字符过滤

    //匹配中文 数字 字母 下划线 var checkInput = function (str) { var pattern =var pattern = /^[\w\u4e00-\u9fa5]+$/ ...

  6. 如何用SQL为每一行均产生一个随机数

    ) as int) as RndId from 表名

  7. Linux下Ngnix及PHP重启命令

    INT, TERM 立刻终止 QUIT 平滑终止 USR1 重新打开日志文件 USR2 平滑重载所有worker进程并重新载入配置和二进制模块 php-fpm 关闭: kill -INT `cat / ...

  8. 涉及到复制和二进制日志中的选项和变量-Replication and Binary Logging Options and Variables

    在搭建复制中,有些参数需要我们留意,在这里罗列出来,供大家参考一下,以GTID为基础 --server-id server-id:这是一个全局的可动态调整的变量,取值范围为0-4294967295,也 ...

  9. Ubuntu系统下完全卸载和安装Mysql

    删除 mysql sudo apt-get autoremove --purge mysql-server-5.0 sudo apt-get remove mysql-server sudo apt- ...

  10. Summaries On Java

    @1:== 和 equals(): ==用于比较引用和比较基本数据类型时具有不同的功能: 比较基本数据类型:如果两个值相同,则结果为true. 比较引用:如果引用指向内存中的同一对象,结果为true( ...