暴力递归,直接GG
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int tmp[1005]; int ans = 0; void fuc(int n){ if(n == 1){ return; } int tmp = n/2; for(int i=1;i<=tmp;i++){ ans++; fuc(i); } } int main(void){ int n; cin >> n; fuc(n); ans++; cout << ans; return 0; }
递推AC
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int ans = 0; int tmp[1005]; int main(void){ int n; cin >> n; for(int i=1;i<=n;i++){ for(int j=1;j<=i/2;j++){ tmp[i] += tmp[j]; } tmp[i]++; } cout << tmp[n]; return 0; }