hdoj.1293 The Number of Paths【大数+排列组合】 2015/08/07
来源:互联网 发布:thinkphp3.2项目源码 编辑:程序博客网 时间:2024/06/05 06:27
The Number of Paths
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 595 Accepted Submission(s): 273
Problem Description
Let f (n) be the number of paths with n steps starting from O (0, 0), with steps of the type (1, 0), or (-1, 0), or (0, 1), and never intersecting themselves. For instance, f (2) =7, as shown in Fig.1. Equivalently, letting E=(1,0),W=(-1,0),N=(0,1), we want the number of words A1A2...An, each Ai either E, W, or N, such that EW and WE never appear as factors.
Input
There are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of steps(1<=n<=1000).
Output
For each test case, there is only one integer means the number of paths.
Sample Input
12
Sample Output
37
Author
SmallBeer (CML)
Source
杭电ACM集训队训练赛(VIII)
注:f(n) = 2*f(n-1)+f(n-2)
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int p[1010][500];int main(){ //int p[1010][500]; memset(p,0,sizeof(p)); p[0][1] = 1; p[1][1] = 3; p[0][0] = p[1][0] = 1; for( int i = 2 ; i <= 1000 ; ++i ){ for( int j = 1 ; j <= p[i-1][0] ; ++j ) p[i][j] = p[i-1][j] * 2 + p[i-2][j]; for( int j = 1 ; j <= p[i-1][0] ; ++j ){ if( p[i][j] > 9 ){ p[i][j+1] += p[i][j] / 10; p[i][j] %= 10; } } p[i][0] = p[i][p[i-1][0]+1] ? p[i-1][0] + 1 : p[i-1][0] ; } int n; while(cin>>n){ for( int i = p[n][0] ; i > 0 ; --i ) printf("%d",p[n][i]); printf("\n"); } return 0;}
0 0
- hdoj.1293 The Number of Paths【大数+排列组合】 2015/08/07
- HDU 1293 The Number of Paths
- The Number of Paths - HDU 1293 DP
- hdu 1293 The Number of Paths
- SGU 407 Number of Paths in the Empire dp+java大数
- hdoj.1297 Children’s Queue【大数+排列组合】 2015/08/06
- SGU 407-Number of Paths in the Empire【DP】
- hdoj 3006 The Number of set(位运算+枚举)
- HDOJ 3948 The Number of Palindromes 后缀数组
- HDOJ 3948 The Number of Palindromes 回文串自动机
- hdu 1492 The number of divisors(约数) about Humble Numbers (数学:排列组合)
- HDOJ 1018 Big Number(大数)
- HDOJ 1212 Big Number (大数求模)
- HDOJ 1018 Big Number (大数位数)
- hdoj 4151 The Special Number
- hdoj-1562-Guess the number
- HDOJ 1562 Guess the number
- The number of steps
- BFS模版程序
- 一分钟让你了解Microsoft Edge
- (一) Simple build files(简单的构建文件)
- 关于AVFoundation播放没有声音的解决办法
- 100 Same Tree
- hdoj.1293 The Number of Paths【大数+排列组合】 2015/08/07
- 安装程序无法创建新的系统分区,也无法定位现有系统分区
- C++ http socket 文件上传和下载 FILE写文件失败
- ORA-12704: 字符集不匹配
- hdu 4764——Stone
- Linux必备软件之SSH
- TCP状态转换图详解
- oracle_over
- 内支付三:In-App Purchase Walk Through 整个支付流程