HDU 2501 Tiling_easy version
2015-02-13 16:35
337 查看
#include <stdio.h> int main() { __int64 s[31]={0,1,3}; int n,t; for (n=3;n<=30;n++) { s =2*s[n-2]+s[n-1]; } scanf("%d",&t); while (t--) { scanf("%d",&n); printf("%I64d\n",s ); } return 0; }
2:模拟
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> long long i,j,num,x,y,n,m,a[200]; int dfs(long long z) { long long k; if(z==i) { num++; return; } if(z>i) return; else for(k=1;k<=3;k++) { if(k==1) dfs(z+1); else dfs(z+2); } return; } int main() { for(i=1;i<30;i++) { num=0; for(j=1;j<=3;j++) { if(j==1) dfs(1); else dfs(2); } a[i]=num; } for(x=1;x<30;x++) printf("%I64d\n",a[x]); }
</pre><pre name="code" class="cpp">#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> long long a[50]={1,3,5,11,21,43,85,171,341,683,1365,2731,5461, 10923,21845,43691,87381,174763,349525,699051, 1398101,2796203,5592405,11184811,22369621,44739243, 89478485,178956971,357913941,715827883}; int main() { int n,k; while(scanf("%d",&n)!=EOF) { while(n--) { scanf("%d",&k); printf("%I64d\n",a[k-1]); } } }
这程序要跑一会儿,不想等的改成20
发现f
=2f
+1(-1)(1或者-1两者之间波动)
数据如下:
1
3
5
11
21
43
85
171
341
683
1365
2731
5461
10923
21845
43691
87381
174763
349525
699051
1398101
2796203
5592405
11184811
22369621
44739243
89478485
178956971
357913941
715827883
很坑爹的一道找规律的题目。
注意的是 一开始 我都用_int64(long long)进行赋值了 不应该 导致后面出错
因为long long 得用printf("%lld", a)或者printf("%I64d", a)两种
第二种方法是直接打表 用于超时答案对的情况
相关文章推荐
- hdu 2501 Tiling_easy version(简单dp)
- HDU-2501 Tiling_easy version 递推
- hdu-2501-Tiling_easy version
- HDU 2501 Tiling_easy version
- HDU 2501--Tiling_easy version【递推】
- hdu 2501--Tiling_easy version
- hdu--2501--Tiling_easy version
- hdu 2501 Tiling_easy version
- hdu 2501 Tiling_easy version 递推
- hdu 2501 Tiling_easy version (水题)
- 递推--HDU 2501Tiling_easy version
- HDU 2501 Tiling_easy version(dp)
- HDU 2501 Tiling_easy version (递推)
- HDU - 2501 - Tiling_easy version (简单递推关系!!)
- (step 3.1.6)hdu 2501(Tiling_easy version)
- hdu-2501-Tiling_easy version
- HDU 2501 Tiling_easy version
- hdu 2501 Tiling_easy version
- HDU 2501 Tiling_easy version
- hDU 2501-Tiling_easy version