【高精度+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 ...
随机推荐
- 关于使用STL常见的两个bug
1.bug 1 class CTest { public : vector<int> getVector() const //需要写成引用形式,不然下面begin.end调用会以拷贝形式调 ...
- 《JavaScript 闯关记》之垃圾回收和内存管理
JavaScript 具有自动垃圾收集机制(GC:Garbage Collecation),也就是说,执行环境会负责管理代码执行过程中使用的内存.而在 C 和 C++ 之类的语言中,开发人员的一项基本 ...
- undefined和null的区别
在javascript中undefined和null几乎是没有区别的 undefined==null;//true; 区别: null是一个表示“无”的对象,转为数值为0:或者说没有对象,此处 ...
- C#解决MDI窗体闪屏的方法
最近从师兄手上接了一个C#的项目,需要用到MDI窗体,可是每当我显示子窗体的时候会有一次“闪烁”,很明显,看起来非常不爽,查找许久,知道是每次在show()子窗体的时候都会调用子窗体构造函数重绘窗体, ...
- Android开发实现透明通知栏
这个特性是andorid4.4支持的,最少要api19才可以使用,也就是说如果Android的机子是低于4.4,沉浸通知栏是没有效果的.下面介绍一下使用的方法,非常得简单. public void i ...
- iOS-OC-基础-NSNumber常用方法
/*===========================NSNumber数值对象=========================*/ // 将基本数据类型保存为NSNumber 对象类型 NSNu ...
- SQL Server一些常见却不太记得住的命令
一.数据库大小查询 1. exec sp_spaceused '表名' --(SQL统计数据,大量事务操作后可能不准)2. exec sp_spaceused '表名', true ...
- CTL_CODE 宏 详解
CTL_CODE宏 CTL_CODE:用于创建一个唯一的32位系统I/O控制代码,这个控制代码包括4部分组成: DeviceType(设备类型,高16位(16-31位)), Function(功能2- ...
- POJ Find The Multiple 1426 (搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22576 Accepted: 929 ...
- mysql 在启动时配置文件的查找方式
知识储备: 1.mysql在启动时会去多个地方找它的配置文件,当然啦这些也都是可以从帮助中找到的,问题在于我们要知道怎么找到对应的帮助才行啊 实战: [root@workstudio data]# m ...