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. 七、Dockerfile案例一(jdk1.8安装)

    七.Dockerfile案例一(jdk1.8安装) 1 获取一个简单的Docker系统镜像,并建立一个容器. 这里我选择下载CentOS镜像 docker pull centos 通过docker t ...

  2. C语言8.3冒泡排序

    8.3.1 例8-5 题目:输入n个正整数,将他们从小到大排序后输出,要求使用冒泡排序法. 而在自己抄写代码的时候,出现了以下问题: # include<stdio.h> void bub ...

  3. RabbitMQ安装篇

    一切不是自己实战,且跑不起来的程序都是在耍流氓! 先下载: http://www.erlang.org/downloads     erlang 包

  4. 路径规划 Adjacency matrix 传球问题

    建模 问题是什么 知道了问题是什么答案就ok了 重复考虑 与 重复计算 程序可以重复考虑  但往目标篮子中放入时,放不放把握好就ok了. 集合 交集 并集 w 路径规划 字符串处理 42423 424 ...

  5. C#加快Bitmap的访问速度

    在对Bitmap图片操作的时候,有时需要用到获取或设置像素颜色方法:GetPixel 和 SetPixel, 如果直接对这两个方法进行操作的话速度很慢,这里我们可以通过把数据提取出来操作,然后操作完在 ...

  6. echarts3.8.4实现模拟迁移

    动态接受城市的经纬度https://zhidao.baidu.com/question/1384875311724922940.html 调用百度api获得ip对应的城市https://www.cnb ...

  7. Yii2 自定义独立验证器

    新建一个文件: ?php /** * author : forecho <caizhenghai@gmail.com> * createTime : 2015/7/1 14:54 * de ...

  8. PHP/Yii2操作Cookie,常见问题以及注意事项

    设置Cookie PHP setcookie("name", "Larry",time()+3600 Yii2 $cookies = Yii::$app-> ...

  9. 如何安装/更新ruby,安装cocoapods,为开发做好准备!(2016年12月07日更新内容)

    一:首先来说一下如何安装/更新ruby: 一般情况下,即使是新买的Mac电脑也会安装有ruby,可以在终端中键入一下命令查看ruby版本 ruby -v 正常情况下下面会打印出ruby的版本信息,如果 ...

  10. mysql插入一张表里的数据到另一张表

    公司的一个项目,做报表--要关联的表结构比较多,最后决定把要用的数据集合到一张新表中,需要用到以下的sql语法......分享下: web开发中,我们经常需要将一个表的数据插入到另外一个表,有时还需要 ...