提交时间:2024-02-22 20:52:40

运行 ID: 41646

#include<bits/stdc++.h> using namespace std; int main(){ int k[105] = {1},n = 0; long long ans[105] = {0}; ans[1] = 1; ans[2] = 2; ans[3] = 4; while(1){ int l; cin>>l; if(!l){ break; } k[n] = l; n++; } for(int i = 0;i<n;i++){ if(ans[k[i]]){ cout<<ans[k[i]]<<endl; continue; } for(int j = 4;j<=k[i];j++){ ans[j] = ans[j-1]+ans[j-2]+ans[j-3]; } cout<<ans[k[i]]<<endl; } }