【高精度+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 ...
随机推荐
- cocos2dx 编写shader 遇到 溢出问题
在 编程语言中,不论什么 数据类型 都有 各种 的 局限,无法 表示 现实世界中的 不论什么 情况. 比如 int ,char 会 溢出,float 会 有 溢出 以及 精度 不准确的 情况. 所以 ...
- linux TIME_WAIT过多的解决方法
查看TCP状态:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'查看SOCKET状态:cat /proc/n ...
- ASP.NET内核几大对象、ASP.NET核心知识(6)--转载
这篇博文主要介绍一下几个对象. 1)HttpContext 2)HttpRequest 3)HttpResponse 4)context. Server 5)context.Session HttpC ...
- git学习笔记(五)
---恢复内容开始--- 嗯 今天又看到一个非常不错的入门git教程 Mark一下 阮一峰Git操作详解 主要讲解了五个常用的git命令 git clone git remote git fetch ...
- 【问题备注】VS2012不能输入代码,文字…
第一次遇到,非常奇怪,一个项目,VS2012能正常打开,但是不能输入代码. 对比分析发现,其他项目能正常work.在于一个问题就是,VS2012 右下角有个INS一直在转一直analyzing,而正常 ...
- ActiveMQ发布订阅模式(转)
ActiveMQ的另一种模式就SUB/HUB即发布订阅模式,是SUB/hub就是一拖N的USB分线器的意思.意思就是一个来源分到N个出口.还是上节的例子,当一个订单产生后,后台N个系统需要联动,但有一 ...
- OpenCV——CvSeq动态结构序列
动态结构序列CvSeq是所有OpenCV动态数据结构的基础. 分为两类: 稠密序列 稀疏序列 (1) 稠密序列都派生自CvSeq,他们用来代表可扩展的一维数组 - 向量.栈.队列和双端队列.数据间不存 ...
- C++中类的内存空间大小(sizeof)分析
注意类大小与结构体大小还是有一些不同的,类里面还包含成员函数(特别是虚函数),结构体中一般只有数据成员. 首先明确各数据类型占多大的空间.例如int到底是占2字节还是4字节空间: 在TC里,int是2 ...
- http://python3-cookbook.readthedocs.io/zh_CN/latest/c14/p01_testing_output_sent_to_stdout.html
http://python3-cookbook.readthedocs.io/zh_CN/latest/c14/p01_testing_output_sent_to_stdout.html draw. ...
- (原)下载pubFig的python代码
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5715305.html pubFig数据库网址: http://www.cs.columbia.edu/ ...