hdu 1709 母函式
The Balance
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7220 Accepted Submission(s): 2980
Problem Description Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality of all the weights.
Input The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality of each weight where 1<=Ai<=100.
Output For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.
Sample Input 3 1 2 4 3 9 2 1
Sample Output 0 2 4 5 題意:有一個天平來稱物體重量,有n種砝碼,每種砝碼只有一個,由於每個砝碼都可以放在左右兩邊,所以不僅要相加還要相減。
用到母函式(1+x^n1)*(1+x^n2)*……*(1+x^nn),由於能力有限只能計算出那個物體能稱出來,不能算出方法有幾種。
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> using namespace std; int a[10001]; int c1[10001],c2[10001]; int c3[10001]; int main() { int n; while(scanf("%d",&n)==1) { memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); int sum=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; } c1[0]=1;c1[a[1]]=1; for(int i=2;i<=n;i++) { for(int j=0;j<=sum;j++) { for(int k=0;k+j<=sum&&k<=a[i];k+=a[i]) { c2[abs(j-k)]+=c1[j]; c2[j+k]+=c1[j]; } } for(int j=0;j<=sum;j++) { c1[j]=c2[j];c2[j]=0; } } int cnt=0; for(int i=1;i<=sum;i++) { if(c1[i]==0) { c3[++cnt]=i; } } if(cnt==0) { printf("0\n"); } else{ printf("%d\n",cnt); for(int i=1;i<=cnt;i++) { if(i!=1) printf(" "); printf("%d",c3[i]); } printf("\n"); } } return 0; }
相關推薦
hdu 1709 母函式
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7220 Accepted S
hdu 1171 Big Event in HDU 【母函式】
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1171 題意:航電計算機學院要分成軟體學院和計算機學院,要分物資,計算機學院的物資不少於比軟體學院的(儘可能平均的請款下) 思路:母函式做一發,基本套模板,記錄一下數量和價值還有總價值即可 #
HDU 1028 母函式做法
題目連結 http://acm.hdu.edu.cn/showproblem.php?pid=1028 其實就是母函式模板,當然用DP也能做。 AC程式碼 https://github.com/Kiritow/OJ-Problems-Source/blob/master/H
HDU 1028 母函式
Ignatius and the Princess IIIProblem Description "Well, it seems the first problem is too easy. I will let you know how foolish you are
hdu 1028 母函式模板
#include <iostream> #include <cstring> #define mem(x, k) ((x), (k), sizeof(x)) #define M
HDU 1171 Big Event in HDU(母函式||DP)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22991 Accep
hdu 1028 母函式入門題
題意:給出n n<=120,拆分n的方法數? (1+x^2+x^3+..x^n) *(1+x^2+x^4+x^6+...) *(1+x^3+x^6+...) 第i個表示式代表了數i的選法:1代表不選i,1後的第j項(x^(ji))表示選j個i,求x^n的係數即可
hdu 1709(普通型母函式)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3249 Accepted Su
hdu 1709 (母函式,有些特殊)
母函式。。 #include"stdio.h" #include"string.h" int main() { int a[10008]; int b[10008]; in
HDU 1709 (母函式)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot
hdu 1521 排列組合【指數型母函式】
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1521 指數型母函式定義及其作用: #include<stdio.h> #include<string.h> #include<string&
2017多校訓練賽第一場 HDU 6042 (母函式)
Journey with Knapsack Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 164 A
排列組合 HDU - 1521 -指數型母函式
排列組合 HDU - 1521 一句話區分指數型母函式和母函式就是 母函式是組合數,指數型母函式是排列數 #include<bits/stdc++.h> using namespace std; #define maxn 12 dou
hdu 1028(普通型母函式)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6
杭電ACM hdu 2152 Fruit 解題報告(母函式)
Problem Description 轉眼到了收穫的季節,由於有TT的專業指導,Lele獲得了大豐收。特別是水果,Lele一共種了N種水果,有蘋果,梨子,香蕉,西瓜……不但味道好吃,樣子更是好看。 於是,很多人們慕名而來,找Lele買水果。 甚至連大名鼎鼎的HDU ACM
HDU 2152(母函式)
Problem Description 轉眼到了收穫的季節,由於有TT的專業指導,Lele獲得了大豐收。特別是水果,Lele一共種了N種水果,有蘋果,梨子,香蕉,西瓜……不但味道好吃,樣子更是好看。 於是,很多人們慕名而來,找Lele買水果。 甚至連大名鼎鼎的HDU ACM
B.找單詞——(HDU 2082 普通型母函式)
傳送門 找單詞 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S
hdu 1028 Ignatius and the Princess III ( 母函式)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12
HDOJ 題目1709 The Balance(母函式)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5756 Accepted Su
hdu 1171(普通型母函式)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11501 Acce