HDU 5890 Eighty seven
预处理,$01$背包,$bitset$优化。
可以预处理出每一种询问的答案,用$01$背包计算答案,$dp[i][j][k]$表示,前$i$个数字中,选择了$j$个,能否凑出$k$这个数字,可以开成$bitset<90>dp[55][12]$,第三维$bitset$位运算优化。
$HDU$不稳,有时超时,有时通过。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
int T,n,s[];
bool f[maxn][maxn][maxn],g[maxn][maxn][maxn]; bool get(int a,int b,int c)
{
bitset<>dp[maxn][]; int p[], sz=;
for(int i=;i<=n;i++)
{
if(s[i]>) continue;
if(i==a) continue;
if(i==b) continue;
if(i==c) continue;
p[sz++]=s[i];
} if(sz==) return ; dp[][][p[]]=;
for(int i=;i<sz;i++)
{
dp[i][]|=dp[i-][]; dp[i][][p[i]]=;
for(int j=;j<=;j++)
{
dp[i][j]|=dp[i-][j];
dp[i][j]|=dp[i-][j-]<<p[i];
}
if(dp[i][][]==) return ;
}
return ;
} int main()
{
scanf("%d",&T);
for(int i=;i<=T;i++)
{
memset(f,,sizeof f);
memset(g,,sizeof g); scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&s[i]); int Q; scanf("%d",&Q);
while(Q--)
{
int op[]; scanf("%d%d%d",&op[],&op[],&op[]);
sort(op,op+); if(g[op[]][op[]][op[]])
{
if(f[op[]][op[]][op[]]==)printf("No\n");
else printf("Yes\n");
}
else
{
f[op[]][op[]][op[]]=get(op[],op[],op[]);
if(f[op[]][op[]][op[]]==)printf("No\n");
else printf("Yes\n");
g[op[]][op[]][op[]]=;
}
}
}
return ;
}
HDU 5890 Eighty seven的更多相关文章
- hdu 5890 Eighty seven 暴力+bitset优化背包
Eighty seven Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others) P ...
- HDU 5890 Eighty seven(DP+bitset优化)
题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using nam ...
- hdu 5890 01背包 bitset
注意不能每个T都mem 不然会T #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b, ...
- 【CQ18阶梯赛第8场】题解
[A:HDU2032 杨辉三角]: 简单的递推,或者是基础的DP: 但是只有杨润东一个人1A,整体准确率只有8/37,具体原因不详. 经验:提交前一定要试一下比较特殊的数据或者最大的数据.其次,为了保 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- [转]iOS Anti-Debugging Protections
source-1: http://www.coredump.gr/articles/ios-anti-debugging-protections-part-1/ source-2: http://ww ...
- CentOS安装Python教程
下载/安装python yum install -y bzip2* #nodejs 0.8.5需要,请安装python前,先安装此模块. wget http://www.python.org/ft ...
- iOS手动管理内存
虽然iOS已经有了ARC帮你自动管理内存,但在有些项目中必须采用手动的方式,而且在懂得手动管理内存的情况下会是自己的代码更加完善 众所周知,基于手动管理内存的情况下必然涉及到 relese reta ...
- 专为webkit内核而生的javascript库mango正式发布
专为webkit内核而生的javascript库mango正式发布 Mango(芒果) javascript库 求fork https://github.com/willian12345/mango ...
- hibernate查询出的数据和数据库不一致
之前直接使用hibernate的时候就出现过已经进行物理存储后的数据,查询不出来的情况,既然是已经存储后的数据,说明事务已经提交,想必问题出在查询时,查询的缓存,没有查询数据库.时有时无就很奇怪. 现 ...
- nginx-push-stream模块源码学习(三)——发布
一.概述 发布:发布者将MSG post到某一特定通道上,channel将信息缓存 在说明发布流程之前有必要说明下channel和msg的数据结构. 二.数据结构 2.1 MSG 发布 ...
- 博客已迁移到lizhug.com
新的博客地址 http://lizhug.com
- 简单实现TCP下的大文件高效传输
简单实现TCP下的大文件高效传输 在TCP下进行大文件传输不象小文件那样直接打包个BUFFER发送出去,因为文件比较大所以不可能把文件读到一个BUFFER发送出去.主要有些文件的大小可能是1G,2G或 ...
- django User model
django User model operation this tutorial will guide us to know how to manipulate django User model. ...
- Java-调用抽象类中指定参数的构造方法
abstract class person { private String name; private int age; public person(String name,int age) ...