Skip to content

Commit

Permalink
Create ex2.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
haodayizhia authored Sep 6, 2022
1 parent 3e4b370 commit a3eb2a3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions ex2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
```cpp
#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 - j.first / jy[i - 1]))
count += j.second;
}
}
std::cout << count << endl;
return 0;
}
```

0 comments on commit a3eb2a3

Please sign in to comment.