【高精度+DP】【HDU1223】 OrderCount
Order Count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 661 Accepted Submission(s): 248
Problem Description
If we connect 3 numbers with "<" and "=", there are 13 cases:
1) A=B=C
2) A=B<C
3) A<B=C
4) A<B<C
5) A<C<B
6) A=C<B
7) B<A=C
8) B<A<C
9) B<C<A
10) B=C<A
11) C<A=B
12) C<A<B
13) C<B<A
If we connect n numbers with "<" and "=", how many cases then?
Input
The input starts with a positive integer P(0<P<1000) which indicates the number of test cases. Then on the following P lines, each line consists of a positive integer n(1<=n<=50) which indicates the amount of numbers to be connected.
Output
For each input n, you should output the amount of cases in a single line.
Sample Input
2
1
3
Sample Output
1
13
Hint
Hint
Huge input, scanf is recommended.
Author
weigang Lee
Source
213
113Huge input, scanf is recommended.HintHint
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
const int maxn=52;
const int L = 25;
const int B = 10000;
using namespace std;
struct Bigint
{
int operator[](int index) const {
return digit[index];
} int& operator[](int index) {
return digit[index];
}
int len;
int digit[L];
};
Bigint F[52][52];
void MEMSET(Bigint &a)
{
a.len=1;
memset(a.digit,0,sizeof(a.digit));
}
void add(Bigint &d,const Bigint &a,const Bigint &b)
{
int temp;
Bigint c;
MEMSET(c);
c.len=max(a.len,b.len)+1;
for(int i=0,temp=0;i<c.len;i++)
{
temp+=a[i]+b[i];
c[i]=temp%B;
temp=temp/B;
}
if(c[c.len-1]==0) c.len--;
d=c;
}
void highXlow(Bigint &d,Bigint &a,int &b)
{
int temp;
Bigint c;
MEMSET(c);
c.len=a.len+1;
for(int i=0,temp=0;i<c.len;i++)
{
temp+=a[i]*b;
c[i]=temp%B;
temp=temp/B;
}
if(c[c.len-1]==0) c.len--;
d=c;
}
Bigint ANS[52];
void YCL()
{
F[1][1].digit[0]=1;
F[1][1].len=1;
ANS[1].digit[0]=1;
ANS[1].len=1;
for(int i=2;i<=50;i++)
for(int j=1;j<=i;j++)
{
add(F[i][j],F[i-1][j],F[i-1][j-1]);
highXlow(F[i][j],F[i][j],j);
add(ANS[i],ANS[i],F[i][j]);
}
}
void outputBigint(Bigint &ans)
{
if(ans.len>=1) printf("%d",ans[ans.len-1]);
for(int i=ans.len-2;i>=0;i--)
printf("%04d",ans[i]);
printf("\n");
}
int main()
{
int T,n;
cin>>T;
YCL();
while(T--)
{
cin>>n;
outputBigint(ANS[n]);
}
return 0;
}
【高精度+DP】【HDU1223】 OrderCount的更多相关文章
- Hdu 5568 sequence2 高精度 dp
sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...
- sequence2(高精度dp)
sequence2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- uva 10069 Distinct Subsequences(高精度 + DP求解子串个数)
题目连接:10069 - Distinct Subsequences 题目大意:给出两个字符串x (lenth < 10000), z (lenth < 100), 求在x中有多少个z. ...
- POJ 1625 Censored!(AC自动机+高精度+dp)
http://poj.org/problem?id=1625 题意: 给出一些单词,求长度为m的串不包含这些单词的个数. 思路: 这道题和HDU 2243和POJ 2778是一样的,不同的是这道题不取 ...
- 【Luogu】P1005矩阵取数游戏(高精度+DP)
题目链接 yeah终于过辣! DP,f[i][j]表示每行还剩i到j这个区间的数没取的时候的值.借这个题我也把高精度的短板弥补了一下,以后高精加高精乘应该是没问题了. 哇终于不怂高精了…… 放上代码. ...
- POJ 1737 Connected Graph(高精度+DP递推)
题面 \(solution:\) 首先做个推销:带负数的压位高精度(加减乘+读写) 然后:由 \(N\) 个节点组成的无向图的总数为: \(2^{N*(N-1)/2}\) (也就是说这个图总共有 \( ...
- POJ 1625 Censored! (AC自己主动机 + 高精度 + DP)
题目链接:Censored! 解析:AC自己主动机 + 高精度 + 简单DP. 字符有可能会超过128.用map映射一下就可以. 中间的数太大.得上高精度. 用矩阵高速幂会超时,简单的DP就能解决时间 ...
- TYVJ 矩阵取数 Label:高精度+dp
题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...
- UVA 10497 - Sweet Child Makes Trouble 高精度DP
Children are always sweet but they can sometimes make you feel bitter. In this problem, you will see ...
随机推荐
- 微信小程序demo豆瓣图书
最近微信小程序被炒得很火热,本人也抱着试一试的态度下载了微信web开发者工具,开发工具比较简洁,功能相对比较少,个性化设置也没有.了解完开发工具之后,顺便看了一下小程序的官方开发文档,大概了解了小程序 ...
- eclipse安装Flash Builder 4后变成中文,怎么解决
修改eclipse.ini启动参数: -startup plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar --launcher.libr ...
- Volley报错!!!No address associated with hostname
年轻人检查你的网络去吧,这是没有网络导致的原因
- Mysql 建表时,日期时间类型选择
mysql(5.5)所支持的日期时间类型有:DATETIME. TIMESTAMP.DATE.TIME.YEAR. 几种类型比较如下: 日期时间类型 占用空间 日期格式 最小值 最大值 零值表示 D ...
- 居然因为交换错了好几把。。。。,还有坑点是num1可以大于num2
完数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- js智能提示代码
<reference path = "../../../Scripts/jQuery-1.4.1.js"/>
- 无法添加sql server ER图
Database diagram support objects cannot be installed because this database does not have a valid own ...
- HttpClient post中文乱码解决
在javase方式下使用HttpClient没有进行任何编码设置,本地从服务端获取到数据不存在中文乱码. 但是将此段代码部署到Tomcat下面出现了中文乱码,此时设置: post.getParams( ...
- MySQL调试
http://dev.mysql.com/doc/refman/5.5/en/signal.html#signal-condition-information-items http://www.dev ...
- C# unsafe code
(*) unsafe 和 fixed unsafe { ]; ; i < array.Length; i++) { arra ...