hdu 2067小兔的棋盘
2016-08-12 14:26
363 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2067
Problem Description
小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(0,0)走到终点(n,n)的最短路径数是C(2n,n),现在小兔又想如果不穿越对角线(但可接触对角线上的格点),这样的路径数有多少?小兔想了很长时间都没想出来,现在想请你帮助小兔解决这个问题,对于你来说应该不难吧!
Input
每次输入一个数n(1<=n<=35),当n等于-1时结束输入。
Output
对于每个输入数据输出路径数,具体格式看Sample。
Sample Input
1
3
12
-1
Sample Output
1 1 2
2 3 10
3 12 416024
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll dp[40][40];
void init()
{
for(int i=1;i<40;i++) dp[1][i]=1;
for(int i=2;i<40;i++)
for(int j=i;j<40;j++)
dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
int main()
{
// freopen("1.txt","r",stdin);
init();
int n,casetime=1;
while(scanf("%d",&n),n+1)
{
printf("%d %d ",casetime++,n);n++;
ll ans=dp
*2;
cout<<ans<<'\n';
}
return 0;
}
Problem Description
小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(0,0)走到终点(n,n)的最短路径数是C(2n,n),现在小兔又想如果不穿越对角线(但可接触对角线上的格点),这样的路径数有多少?小兔想了很长时间都没想出来,现在想请你帮助小兔解决这个问题,对于你来说应该不难吧!
Input
每次输入一个数n(1<=n<=35),当n等于-1时结束输入。
Output
对于每个输入数据输出路径数,具体格式看Sample。
Sample Input
1
3
12
-1
Sample Output
1 1 2
2 3 10
3 12 416024
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll dp[40][40];
void init()
{
for(int i=1;i<40;i++) dp[1][i]=1;
for(int i=2;i<40;i++)
for(int j=i;j<40;j++)
dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
int main()
{
// freopen("1.txt","r",stdin);
init();
int n,casetime=1;
while(scanf("%d",&n),n+1)
{
printf("%d %d ",casetime++,n);n++;
ll ans=dp
*2;
cout<<ans<<'\n';
}
return 0;
}
相关文章推荐
- Objective-C Runtime的知识
- 【机器学习实战02】k-近邻算法
- 51Nod-1393-0和1相等串
- chattr权限设定
- 滑盖式便携式美容雾化器霍尔开关 MH251
- react+redux教程(一)connect、applyMiddleware、thunk、webpackHotMiddleware
- mybatis连接配置
- FFmpeg+x264编译Android库
- IntelliJ idea 2016.2.1 激活
- 关于TbSchedule任务调度管理框架的整合部署
- opencv surf特征点匹配拼接源码
- Putty工具包PSCP向Linux上传文件
- Github+Jekyll —— 创建个人免费博客(二)Ruby+Jekyll部署
- Spring JdbcTemplate使用别名传参(NamedParameterJdbcTemplate)
- Retrieving File Information
- 将eclipse项目导入到android studio
- Linux管道命令
- 8大排序之---(2)希尔排序
- Zookeeper启动报错
- Opencv图像识别从零到精通(25)------区域分裂与合并