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. Sharepoint server 2016自定义作业不能部署

    最近帮客户部署SharePoint server 2016生产环境,自定义作业总是不能部署上,原来我在部署过程中MinRole选的是Web前端服务器:经过几天的测试研究,发现要有single serv ...

  2. 《从零开始学Swift》学习笔记(Day 12)——说几个特殊运算符

    原创文章,欢迎转载.转载请注明:关东升的博客   除了一些常用的运算符,还有一些其他的: •      引用号(.):实例调用属性.方法等操作符. •      问号(?):用来声明可选类型. •   ...

  3. vip视频网站爬虫

    vip视频网站爬虫 电影网站:http://www.08ge.com/play/?make=dianying&id=fqvlYhH5QHb3Sh.html 找到<iframe>的i ...

  4. 使用QtConcurrent编写多线程程序(也可以阻塞)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Amnes1a/article/details/66470751Qt在其QtConcurrent命名空 ...

  5. Python 中星号作用:解包&打散

    python中’*’和’**’的使用分两个方面,一个是计算,另一个是参数传递过程中元素的打包和解包.  计算方面 ‘*’和’**’在python中最常见的作用分别是‘相乘’和‘乘幂’,如下: > ...

  6. Java输入输出重定向代码

    try {   BufferedInputStream in = new BufferedInputStream(new FileInputStream("input.txt")) ...

  7. centos7 安装python3.6

    •到python官网找到下载路径, 用wget下载 wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz •解压tgz包 tar ...

  8. 005-快捷键,host,查看版本

    一.系统快捷键 设置 键盘--查看 shift+ctrl +print  区域截图至剪切版 ctrl+alt+箭头     切换工作区 自定义打开终端快捷键 设置->键盘->自定义:名称: ...

  9. [转载]分布式session处理方案

    伴随网站业务规模和访问量的逐步发展,原本由单台服务器.单个域名的迷你网站架构已经无法满足发展需要. 此时我们可能会购买更多服务器,并且启用多个二级子域名以频道化的方式,根据业务功能将网站分布部署在独立 ...

  10. MySQL数据库(3)_MySQL数据库表记录操作语句

    附: MYSQL5.7版本sql_mode=only_full_group_by问题 .查询当前sql_mode: select @@sql_mode .查询出来的值为: set @@sql_mode ...