-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex2.cpp
52 lines (50 loc) · 1.3 KB
/
ex2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
// 升级需要的总经验
int total;
// 升一级的经验值
int z;
// 情况数
int count = 0;
// 经验值集合
vector<int> jy;
cin >> total;
while (cin >> z)
jy.push_back(z);
// 从小到大排列经验值
sort(jy.begin(), jy.end());
int size = jy.size();
// first可能的经验值,second出现的次数
map<int, int> value = {{total, 1}};
for (int i = size; i > 0; --i)
{
// 到小的经验值之前
if (i > 1)
{
auto temp_value = value;
for (auto &j : temp_value)
for (int k = 1; k <= j.first / jy[i - 1]; ++k)
{
int t = j.first - k * jy[i - 1];
if (temp_value.find(t) == temp_value.end())
value.insert(pair<int, int>(t, 1));
else
++value[t];
}
}
// 最后一个经验值,直接整除
else
{
for (auto &j : value)
if (!(j.first % jy[i - 1]))
count += j.second;
}
}
std::cout << count << endl;
return 0;
}