HDU1134 Game of Connections(大数乘法+打表)
来源:互联网 发布:php怎么在浏览器运行 编辑:程序博客网 时间:2024/06/01 23:37
Game of Connections
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5079 Accepted Submission(s): 2913
Problem Description
This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.
It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?
It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?
Input
Each line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.
Output
For each n, print in a single line the number of ways to connect the 2n numbers into pairs.
Sample Input
23-1
Sample Output
25
Source
Asia 2004, Shanghai (Mainland China), Preliminary
Recommend
Eddy
思路:终于把这个题弄出来了,大数乘法的思想是偷的这位大神的。
#include<cstdio>#include<cstring>#include<iostream>using namespace std;typedef long long ll;const int maxn=1e5+10;int dp[110][201];void add(int *sum, int *part){ int carry=0; for(int i=1; i<=199; i++) { int c2=(part[i]+sum[i]+carry)/10; sum[i]=(part[i]+sum[i]+carry)%10; carry=c2; }}void multi(int *p, int *q, int *k){ int limit1=200, limit2=200; for(; q[limit1]==0; limit1--); for(; k[limit2]==0; limit2--); // cout<<limit1<<" "<<limit2<<endl; for(int i=1; i<=limit1; i++) { int part[201]; memset(part, 0, sizeof(part)); for(int j=1; j<=limit2; j++) { part[i+j-1]=q[i]*k[j]; } add(p, part); }}void preprg(){ memset(dp, 0, sizeof(dp)); dp[0][1]=1; for(int i=1; i<=100; i++) { for(int j=0; j<i; j++) { int res[201]; memset(res, 0, sizeof(res)); multi(res, dp[j], dp[i-1-j]); add(dp[i], res); } }}int main(){ preprg();//打表预处理; int n; while(~scanf("%d", &n) && n!=-1) { int ed; for(ed=200; dp[n][ed]==0; ed--); //cout<<dp[n][3]<<endl; for(int i=ed; i>=1; i--) printf("%d", dp[n][i]); printf("\n"); } return 0;}
阅读全文
0 0
- HDU1134 Game of Connections(大数乘法+打表)
- HDU1134——Game of Connections (大数乘法,除法)+ (卡特兰数列)
- hdu1134-Game of Connections
- HDU1134 Game of Connections
- hdu1134 Game of Connections 卡特兰数(大数)
- HDU1134 Game of Connections 高精度+DP
- hdu1134 Game of Connections(Catalan数, 顺便附上大数类模板)
- hdu1134 Game of Connections(卡特兰数)
- hdu1134 Game of Connections(Catalan+高精)
- hdu-1134-Game of Connections(卡特兰数 大数乘法除法)
- [ACM] hdu 1134 Game of Connections(大数+Catalan数)
- Game of Connections(大数java+Catalan数)
- hdu 1134 Game of Connections 【卡特兰数+大数】
- hdoj 1134 Game of Connections(卡特兰数&&大数)
- POJ 2084:Game of Connections 大数+卡特兰数
- poj 2084 Game of Connections (卡特兰数,大数乘除)
- TOJ 1179.Game of Connections(大数模板)
- poj 2084 Game of Connections (卡特兰数、大数)
- Windows下配置jupyter notebook的python3与R运行环境
- mysql 用户管理和权限设置
- 跳跃表
- 不能上到MySQL服务器连接127.0.0.1
- 使用Spring Cloud Security OAuth2搭建授权服务
- HDU1134 Game of Connections(大数乘法+打表)
- 将已有项目改造为Spring Boot项目
- 集合Set
- TreeMap和HashMap源码学习
- Hibernate二级缓存
- linux下模拟丢包,延时命令总结
- ARCore:ARCore的初体验
- 欢迎使用CSDN-markdown编辑器
- sightwords的资源