本文共 991 字,大约阅读时间需要 3 分钟。
有N个学生去食堂,可教官规定:必须2人或3人组成一组,求有多少种不同分组的方法。
一个数,N
一个数,即答案。
6
2
N<=150
1 #include 2 3 int n,ans; 4 5 void DFS(int sum) 6 { 7 if(sum>n) return ; 8 if(sum==n) { ans++; return ; } 9 if(sum+2<=n) DFS(sum+2);10 if(sum+3<=n) DFS(sum+3);11 }12 13 int Presist()14 {15 scanf("%d",&n);16 DFS(0);17 printf("%d\n",ans);18 return 0;19 }20 21 int Aptal=Presist();22 int main(int argc,char*argv[]){;}
1 #include 2 3 int n,ans; 4 long long f[155]; 5 6 int Presist() 7 { 8 scanf("%d",&n); 9 f[2]=f[3]=1;10 for(int i=4; i<=n; ++i) f[i]=f[i-2]+f[i-3];11 printf("%lld\n",f[n]);12 return 0;13 }14 15 int Aptal=Presist();16 int main(int argc,char*argv[]){;}
转载于:https://www.cnblogs.com/Shy-key/p/7593659.html