日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5890】Eighty seven(bitset优化背包)

發(fā)布時(shí)間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5890】Eighty seven(bitset优化背包) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?題干:

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?NN?cards with numbers. The number on the?ii-th card is?aiai. In class, each turn he will remove no more than?33?cards and let students choose any ten cards, the sum of the numbers on which is?8787. 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)t?(t≤5), the number of test cases.?tttest cases follow.?
For each test case, the first line consists an integer?N(N≤50)N(N≤50).?
The second line contains?NN?non-negative integers?a1,a2,...,aNa1,a2,...,aN. The?ii-th number represents the number on the?ii-th card. The third line consists an integer?Q(Q≤100000)Q(Q≤100000). Each line of the next?QQ?lines contains three integers?i,j,ki,j,k, representing Mr.Fib will remove the?ii-th,?jj-th, and?kk-th cards in this turn. A question may degenerate while?i=ji=j,?i=ki=k?or?j=kj=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

題目大意:

50個(gè)數(shù),10W個(gè)詢(xún)問(wèn),每次問(wèn)刪掉第i,j,k個(gè)數(shù)后,是否存在一種選10個(gè)數(shù)和為87的方案,只需要輸出 ’Yes’ 或者 ’No’

解題報(bào)告:

? ?直接可行性背包,然后bitset優(yōu)化一下就可以了。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #include<bitset> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; bitset<111> bs[111]; int a[MAX],n; bool dp[111][111][111]; bool ok(int x,int y,int z) {for(int i = 1; i<=n; i++) bs[i].reset();bs[0][0]=1;for(int i = 1; i<=n; i++) {if(i == x || i == y || i == z) continue;for(int j = 10; j>=1; j--) {bs[j] |= (bs[j-1] << a[i]);}}return bs[10][87]; } int main() {int t;cin>>t;while(t--) {scanf("%d",&n);memset(dp,0,sizeof dp);for(int i = 1; i<=n; i++) scanf("%d",a+i);for(int i = 1; i<=n; i++) {for(int j = i; j<=n; j++) {for(int k = j; k<=n; k++) {dp[i][j][k]=0;if(ok(i,j,k)) dp[i][j][k] = 1;}}}int q,x[4];scanf("%d",&q);while(q--) {for(int i = 1; i<=3; i++) scanf("%d",x+i);sort(x+1,x+4);if(dp[x[1]][x[2]][x[3]] == 1) puts("Yes");else puts("No");}}return 0 ; }

?

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的【HDU - 5890】Eighty seven(bitset优化背包)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。