給一個整數 n
求由任意正整數組成 n 的方法數
如組成 4 的方式有 5 種: z4, 3+1, 2+2, 2+1+1, 1+1+1+1
評分結果(參考) : AC (1ms, 328KB)
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<int> p(201, 0);
p[0] = 1;
for(int i=1; i<=200; i++){
for(int j=1; j<=200; j++){
if(i <= j) p[j] += p[j-i];
}
}
int n;
while(cin >> n){
cout << p[n] << "\n";
}
return 0;
}