感觉东哥缺兄弟了,希望大家都能上岸
#include <bits/stdc++.h> using namespace std; int main() { int tmp; while (cin>>tmp) { string s; s = to_string(tmp); reverse(s.begin(), s.end()); tmp = stoi(s); string ans; while (tmp!=0) { ans = to_string(tmp % 5)+ans; tmp = tmp / 5; } cout << ans << endl; } return 0; }第二题题目要求答案要取余不要忘了,LeetCode518变形,原题是组合,这里是排列,对调两个for循环的位置即可
#include <bits/stdc++.h> using namespace std; int main() { const int mod = 1000000007; int n, m; cin >> n >> m; vector<long long> nums; long long tmp; while (n--) { cin >> tmp; if (tmp > m) { continue; } nums.emplace_back(tmp); } vector<long long> ans(m + 1, 0); ans[0] = 1; for (int j = 1; j <= m; ++j) { for (int i = 0; i < nums.size(); i++) { if (j < nums[i]) { continue; } ans[j] += ans[j - nums[i]] % mod; } } long long c = ans[m] % mod; cout << c << endl; return 0; }
全部评论
(1) 回帖