# HDOJ水题集合9

Solved Problem ID Title Ratio(Accepted / Submitted)
1001 国王陛下的货币改革 86.36%(19/22)
1002 选课时间 66.67%(12/18)
1003 喜欢数学的洪药师 25.00%(4/16)
1004 Holding Bin-Laden Captive! 61.54%(8/13)

#### 1001 国王陛下的货币改革

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 22 Accepted Submission(s) : 19
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

、 9元、 16元 … 289元。

Input

Output

Sample Input
2
10
30
0
Sample Output
1
4
27

Hint

#include<bits/stdc++.h>
using namespace std;
const int maxn = 310;
int a[maxn], b[maxn], c[maxn];
int f[18];
int main(){
for(int i = 1; i <= 17; i++)f[i]=i*i;
for(int i = 0; i < maxn; i++)a[i] = 1;
for(int i = 2; i <= 17; i++){
for(int j = 0; j < maxn; j++){
for(int k = 0; k+j < maxn; k += f[i]){
b[j+k] += a[j];
}
}
for(int j = 0; j < maxn; j++){
a[j] = b[j];  b[j] = 0;
}
}

int n;
while(cin>>n &&n){
cout<<a[n]<<"\n";
}
return 0;
}



#### 1002 选课时间

Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 18 Accepted Submission(s) : 12
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

Input

Output

Sample Input
2
2 2
1 2
2 1
40 8
1 1
2 2
3 2
4 2
5 8
6 9
7 6
8 8
Sample Output
2
445
Author
xhd
Source
ACM程序设计期末考试_热身赛(感谢 xhd & 8600)

//多重背包方案数，重量a的物品有b件
#include<bits/stdc++.h>
using namespace std;
int f[110];
int main(){
int T;  cin>>T;
while(T--){
int n, m;  cin>>n>>m;
memset(f,0,sizeof(f));
f[0] = 1;
for(int i = 1; i <= m; i++){
int a, b;  cin>>a>>b;
for(int j = n; j >= a; j--){
for(int k = 1; k <= b; k++){
if(k*a>j)break;
f[j] += f[j-k*a];
}
}
}
cout<<f[n]<<"\n";
}
return 0;
}



#### 1003 喜欢数学的洪药师

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 16 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

Input

Output

Sample Input
3
1 2 4
3
9 2 1
Sample Output
0
2
4 5

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+10;
int n, a[110], sum;
int vis[maxn], tmp[maxn];//vis表示当前能称得出来的重量
int main(){
while(cin>>n){
memset(vis,0,sizeof(vis));
memset(tmp,0,sizeof(tmp));
sum = 0;
for(int i = 1; i <= n; i++){
cin>>a[i];  sum += a[i];
}
vis[0] = vis[a[1]] = 1;
for(int i = 2; i <= n; i++){
for(int j = 0; j <= sum; j++){
int c1 = j+0, c2 = abs(j-a[i]), c3=j+a[i];//选|不选
tmp[c1] += vis[j];//如果j称的出来，那么加上a[i]就可以称出来
tmp[c2] += vis[j];
tmp[c3] += vis[j];
}
for(int j = 0; j <= sum; j++){
vis[j] = tmp[j];
tmp[j] = 0;
}
}
vector<int>ans;
for(int i = 0; i <= sum; i++)
if(!vis[i])ans.push_back(i);
if(ans.size()==0){
cout<<0<<"\n";
continue;
}
cout<<ans.size()<<"\n";
for(int i = 0; i < ans.size(); i++){
if(i!=0)cout<<" ";
cout<<ans[i];
}
cout<<"\n";
}
return 0;
}



#### 1004 Holding Bin-Laden Captive!

Holding Bin-Laden Captive!
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 8
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”

Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take \$25000000 from Bush!
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
Sample Input
1 1 3
0 0 0
Sample Output
4
Author
lcy

//给出面值1,2,5的硬币a,b,c枚，求不能支付的最小正数
//分类讨论：a==0肯定是1。当a+2b小于4时完全用不到5，直接加一即可，否则就是全都用上。
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
while(cin>>a>>b>>c){
if(a==0&&b==0&&c==0)break;
if(a==0)cout<<"1\n";
else if(a+2*b<4)cout<<a+2*b+1<<"\n";
else cout<<a+2*b+5*c+1<<"\n";
}
return 0;
}


04-22 115

04-20 5792
07-11 149
08-11 178
10-12 23
10-01 794
10-08 1918
04-13 720
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客