hdu 5890 01背包 bitset
2024-10-07 09:05:02
注意不能每个T都mem 不然会T
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
//next_permutation
int t;
int n;
int num[];
bitset<> f[];
int dp[][][];
int ques[];
bool ok(int a, int b, int c, int x)
{
if (x == a || x == b || x == c)
{
return true;
}
return false;
}
void getans()
{
for (int i = ; i <= n; i++)
for (int j = i; j <= n; j++)
for (int k = j; k <= n; k++)
{
for (int l = ; l <= ; l++)
{
f[l].reset();
}
f[][] = ;
for (int l = ; l <= n; l++)
{
for (int p = ; p >= ; p--)
{
if (ok(i, j, k, l) || num[l] > )
{
continue;
}
f[p] |= f[p - ] << num[l];
}
}
if (f[][])
{
dp[i][j][k] = ;
}
else
{
dp[i][j][k] = ;
}
}
}
int main()
{
cin >> t;
while (t--)
{
//mem(dp, 0);
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%d", &num[i]);
}
getans();
int m;
int a, b, c;
scanf("%d", &m);
for (int i = ; i <= m; i++)
{
scanf("%d%d%d", &ques[], &ques[], &ques[]);
sort(ques + , ques + );
if (dp[ques[]][ques[]][ques[]])
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
}
}
最新文章
- TSQL 分组集(Grouping Sets)
- HttpClientUtil简介
- 微信官方demo(php)
- css 多行溢出
- 在VS2103环境中集成Doxygen工具
- bat里如何用相对路径
- wireshark抓包图解 TCP三次握手/四次挥手详解
- 快速生成json实体类
- mysql 刘道成视频教程 第3课
- Android Intent传递对象小结
- Springboot中使用Scheduled做定时任务
- javascript:针对yyyy-MM-dd hh:mm:ss格式的毫秒转换.
- appium遇到click事件,提示";w3cStatus";:400
- Matlab feval函数(转)
- python 使用yield进行数据的流式处理
- Documentation/filesystems/sysfs.txt 文档翻译--sysfs
- Kali-linux破解LM Hashes密码
- 【筛法求素数】【推导】【组合数】UVALive - 7642 - Prime Distance
- Java程序员从笨鸟到菜鸟之(九十六)深入java虚拟机(五)——java本地接口JNI详解
- @RestControllerAdvice注解使用