Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string sum(string s1, string s2) {
- string ans;
- string a, b;
- if(s1.size() >= s2.size()){
- a = s1;
- b = s2;
- }
- else{
- a = s2;
- b = s1;
- }
- int r = 0;
- b = string(a.size() - b.size(), '0') + b;
- for(int i = a.size() - 1; i > -1; --i){
- int res = (int)a[i] + (int)b[i] - 2 * '0' + r;
- if(res <= 9){
- ans = ans + char('0' + res);
- r = 0;
- } else {
- r = res / 10;
- ans = ans + char('0' + res % 10);
- }
- }
- if (r) {
- ans += '1';
- }
- reverse(ans.begin(), ans.end());
- return ans;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- vector<vector<string>> dp(n + 1, vector<string>(n + 1, "0"));
- dp[1][1] = "1";
- dp[0][0] = "1";
- for(int i = 2; i <= n; ++i){
- for(int k = 1; k <= i; k += 2){
- for(int j = 0; j <= k; ++j){
- dp[i][k] = sum(dp[i][k], dp[i- k][j]);
- }
- }
- }
- string sum1 = "0";
- for(int i = 0; i <= n; ++i){
- sum1 = sum(sum1, dp[n][i]);
- }
- cout << sum1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement