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 ;
}

最新文章

  1. 初识ASP.NET MVC
  2. 学习 git基础命令
  3. 如何将已部署在ASM的资源迁移到ARM中
  4. 【转】使用:after清除浮动
  5. NHibernate系列文章二十八:NHibernate Mapping之Auto Mapping(附程序下载)
  6. CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)
  7. lightoj 1016
  8. 在Ubuntu 中安装eclipse, eclipse 文件已经下载好!
  9. Google Protocal Buffer
  10. if---(switch-case)语句初步学习总结
  11. 洛谷-语文成绩-[有奖]洛谷5月月赛:kkksc03的三大神器
  12. php常见面试问题
  13. 有些arp请求报文中为什么会有目的mac地址(不使用广播地址)
  14. ●BZOJ 3561 DZY Loves Math VI
  15. &#39;version&#39; contains an expression but should be a constant
  16. AI外包 人工智能外包 长年承接人工智能项目 北京动点软件
  17. Java 异常处理的重要认识
  18. Poj1258 Agri-Net (最小生成树 Prim算法 模板题)
  19. P2292 [HNOI2004]L语言
  20. Linux ssh下实现免密码登录

热门文章

  1. 【BZOJ4917】Hash Killer IV 乱搞
  2. JS实现全选,全不选
  3. Linux下Solr的安装和配置
  4. Xamarin.Forms学习之Page Navigation(一)
  5. 九度OJ 1360:乐透之猜数游戏 (递归)
  6. 【Python之路】第十三篇--DOM
  7. flex 均分铺满
  8. Exploiting second-order SQL injection 利用二阶注入获取数据库版本信息 SQL Injection Attacks and Defense Second Edition
  9. HashMap 扩容机制
  10. 整理前端css/js/jq常见问题及解决方法(1)