P2347题解
Tian_Stone · · 题解
题目分析
这道题可以使用暴力枚举法,尝试每一种可能,用 book 数组统计。(for 循环嵌套)
代码
#include <bits/stdc++.h> //万能头
using namespace std;
int x[10];
int book[1005];
int main()
{
for(int i = 1; i <= 6; i++)
cin >> x[i];
for(int a = 0; a <= x[1]; a++)
{
for(int b = 0; b <= x[2]; b++)
{
for(int c = 0; c <= x[3]; c++)
{
for(int d = 0; d <= x[4]; d++)
{
for(int e = 0; e <= x[5]; e++)
{
for(int f = 0; f <= x[6]; f++) // 6层for循环,枚举个数
{
book[a + b * 2 + c * 3 + d * 5 + e * 10 + f * 20] = 1; // 数量 * 重量
}
}
}
}
}
}
int ans = 0;
for(int i = 1; i <= 1000 ;i++) // 从 1 开始,排除不选的情况
{
ans += book[i];
}
cout << "Total=" << ans; // 别忘输出 "Total="
return 0;
}