hdu 2045 不容易系列之(3)—— LELE的RPG难题(递推)
2012-05-05 18:52
369 查看
题目分析:直接考虑,定义f
为 n位时,种类数,直接考虑f[n+1],如果第n与第一位相同,则f[n+1]=f[n-1]*2;
否则:f[n+1]=f
....则,f[n+1]=f
+f[n-1]*2;
初始化:f[1]=3 , f[2]=6, f[3]=6;
为 n位时,种类数,直接考虑f[n+1],如果第n与第一位相同,则f[n+1]=f[n-1]*2;
否则:f[n+1]=f
....则,f[n+1]=f
+f[n-1]*2;
初始化:f[1]=3 , f[2]=6, f[3]=6;
#include<iostream> #include<cstdio> using namespace std; int a[1000],b[1000],c[1000]; int main() { __int64 f[60]; f[1]=3; f[2]=6; f[3]=6; for(int i=4;i<=50;i++) f[i]=f[i-1]+f[i-2]*2; int n; while(scanf("%d",&n)!=EOF) { printf("%I64d\n",f ); } system("pasue"); return 0; } //递推式错了:开始以为是f =f[n-1]*n,所以还写了一个类似求阶乘的算法....... /* #include<iostream> #include<cstdio> using namespace std; int arr[1000]; void function(int n) { arr[1]=6; int c=1,temp; for(int i=4;i<=n;i++) { temp=0; for(int j=1;j<=c;j++) { temp+=arr[j]*i; arr[j]=temp%10; temp/=10; } while(temp!=0) { arr[++c]=temp%10; temp/=10; } } if(n%2==0) { temp=arr[1]+6; arr[1]=temp%10; temp/=10; if(temp!=0) for(int i=2;i<=c;i++) { temp+=arr[i]; arr[i]=temp%10; temp/=10; if(temp==0) break; } if(temp!=0) arr[++c]=temp; } for(int i=c;i>=1;i--) printf("%d",arr[i]); printf("\n"); } int main() { int f[4]={0,3,6,6}; int n; while(scanf("%d",&n)!=EOF) { if(n<4) printf("%d\n",f ); else { function(n); } } system("pause"); return 0; }*/
相关文章推荐
- HDU 2045 不容易系列之(3)—— LELE的RPG难题(三色涂方格问题详解)(递推)
- HDU 2045 不容易系列之(3)——LELE的RPG难题【递推】
- HDU 2045 不容易系列之(3)―― LELE的RPG难题(递推 or 动态规划)
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 【递推】
- HDU-2045 不容易系列之(3)—— LELE的RPG难题(递推)
- HDU 2045--不容易系列之(3)—— LELE的RPG难题【递推】
- HDU 2045 不容易系列之(3)—— LELE的RPG难题(递推)
- HDU 2045 不容易系列之(3)―― LELE的RPG难题(递推)
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 递推
- HDU - 2045:不容易系列之(3)—— LELE的RPG难题(递推)
- hdu 2045 不容易系列之(3)—— LELE的RPG难题(递推)
- HDU 2045 不容易系列之(3)—— LELE的RPG难题(递推)
- HDU - 2045: 不容易系列之(3)—— LELE的RPG难题(递推)
- HDU-2045 不容易系列之(3)—— LELE的RPG难题 找规律&递推
- 递推 HDU 2045 不容易系列之(3)—— LELE的RPG难题
- HDU 2045不容易系列之三LELE的RPG难题(趋向于DP的递推)
- hdu 2045不容易系列之(3)—— LELE的RPG难题(递推)
- Hdu_2045 不容易系列之(3)―― LELE的RPG难题(递推)
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 (递推)
- hdu 2045 不容易系列之(3)—— LELE的RPG难题 (递推)