【高精度+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 ...
随机推荐
- 初始——第一款个人开发上线app store
最初学习iOS开发时就听人建议,程序员应该有自己的博客,来记录每天的收获,于人于己都是一件很有意义的事.但当初作为菜鸟一枚,自认为对一些知识的认识尚浅,写博客这种高大上的事和自己八竿子打不着. 现如今 ...
- 写一个简易web服务器、ASP.NET核心知识(4)--转载
第一次尝试(V1.0) 1.理论支持 这里主要要说的关于Socket方面的.主要是一个例子,关于Socket如何建立服务端程序的简单的代码. static void Main(string[] arg ...
- css-文字
<!DOCTYPE html>CSS2-文字 <style>div{ /*文字*/ font-size:120px; /*文字大小*/ font-family:Arial,'方 ...
- jquery文本框验证字符长度和只能输入数字
<input type="text" class="chujia" onkeyup="this.value=this.value.replace ...
- 注册界面的优化之ActionBar组件的应用之(一)ActionBar组件的布局实现
开发步骤: 在res下menu文件夹中创建一个actionbar_menu_register.xml菜单资源文件 在资源文件中添加标签设置一个或多个ActionBar功能选项 //action ...
- Cisco cmd 命令
1.enable 开启全局配置模式:disable 禁用配置模式 2.config进入配置模式 3.line 设置进入用户模式密码:分为 line aux 0;line console 0;line ...
- (转)Ubuntu中使用dpkg安装deb文件提示依赖关系问题,仍未被配置
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5638149.html 参考网址: http://zhidao.baidu.com/link?url=b ...
- (原)vs2013静态及动态链接opencv3.0的库
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5477551.html 静态链接步骤如下: 1. 在“通用配置”-“VC++目录”-“包含目录”中添加: ...
- mysql数据库的连接
public TJb checkjbByschool(long id)throws ClassNotFoundException,SQLException { Class.forName(" ...
- Python学习笔记五,函数及其参数
在Python中如何自定义函数:其格式为 def 函数名(函数参数): 内容