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 ...
随机推荐
- rebbitmq-RPC(C#)
RPC(Remote Procedure Call Protocol)——远程过程调用协议 运行时,一次客户机对服务器的RPC调用,其内部操作大致有如下十步: 1.调用客户端句柄:执行传送参数 2.调 ...
- ASP.NET Web API 基础篇1
ASP.NET Web API 直到我膝盖中了一箭[1]基础篇 无题 蓦然回首,那些年,我竟然一直很二. 小时候,读武侠小说的时候,看到那些猪脚,常常会产生一种代入感,幻想自己也会遭遇某种奇遇,遇到悬 ...
- 学习Linux(一)环境搭建
零基础学习Linux(一)环境搭建 从本文开始我会为大家介绍一下linux环境下详细的集群环境安装.配置.部署到实例演示的整个过程.在此过程中会给大家详细介绍一下Linux的操作技巧和一些工具的使用. ...
- ASP.NET MVC学习笔记-----Filter2
ASP.NET MVC学习笔记-----Filter(2) 接上篇ASP.NET MVC学习笔记-----Filter(1) Action Filter Action Filter可以基于任何目的使用 ...
- IP:网际协议
IP:网际协议 1.概述 IP是TCP/IP协议族中最为核心的协议.所有的TCP,UDP,ICMP,IGMP数据都以IP数据报格式传输. IP提供不可靠,无连接的数据报传送服务. ...
- Cross platform GUI for creating SSL certs with OpenSSL
Someone said: from : https://micksmix.wordpress.com/2012/08/09/xca-cross-platform-gui-for-creating-s ...
- python tornado nginx deployment tornado 的部署在linux Nginx服务器
题外话: 这里分享一个链接是将Flask 和 Apache 用 mod_wsgi 来进行传唤的部署方式,在digital ocean VPS 上的. https://www.digitalocean. ...
- Android开发(22)--seekBar采用handler消息处理操作
本案例简单实现进度条可走,可拖拽的功能,下面请看源码: 布局文件: <RelativeLayout xmlns:android="http://schemas.android.com/ ...
- JVM方法调用栈
摘自深入分析java web技术内幕
- linux服务器开发二(系统编程)--线程相关
线程概念 什么是线程 LWP:Light Weight Process,轻量级的进程,本质仍是进程(在Linux环境下). 进程:独立地址空间,拥有PCB. 线程:也有PCB,但没有独立的地址空间(共 ...