解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; using namespace std; int main() { ll f[50]; int t; cin>>t; int i,n,m; while(t--) { cin>>n>>m f[0]=1; for(i=1;i<=n;i++) { if(i<m) f[i]=2*f[i-1]; if(i==m) f[i]=2*f[i-1]-1; if(i>m) f[i]=2*f[i-1]-f[i-m-1]; } cout<<f[n]<<endl; memset(f,0,sizeof(f)); } return 0; }
0.0分
3 人评分