【高精度+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 ...
随机推荐
- LabVIEW新手5大错误
虽然NI LabVIEW软件长期以来一直帮助工程师和科学家们快速开发功能测量和控制应用,但不是所有的新用户都会遵循LabVIEW编程的最佳方法. LabVIEW图形化编程比较独特,因为只需看一眼用户的 ...
- ORA-00119: invalid specification for system parameter LOCAL_LISTENER
重启oracle是提示错误ORA-00119: invalid specification for system parameter LOCAL_LISTENER. 解决方法: 命令查看错误信息:oe ...
- NET基础课-- 类型基础(NET之美)
1.类型:值类型 引用类型. 分类依据:类型在内存的分配方式.值类型在堆栈,引用类型在托管堆. 名词:栈--所有变量都会被分配在栈上,只不过值类型直接含有数据,引用类型含有一个指向托管堆对象的地址. ...
- [转]Asp.Net调用前台js调用后台代码分享
1.C#前台js调用后台代码 前台js <script type="text/javascript" language="javascript"> ...
- C# 文件操作(一)
1.说明: 写入文件内容,如果文件中有内容,则进行追加,目录是程序集下的目录 public static void WriteLog(string value) { try { //目录是程序集下的D ...
- ASP.NET 后台下载文件方法
void DownLoadFile(string fileName) { string filePath = Server.MapPath(fileName);//路径 //以字符流的形式下载文件 F ...
- BackgroundWorker 后台进程控制窗体label、richtextbook内容刷新
昨天写了一个从文章中提取关键词的程序,写完处理的逻辑后又花了好几个小时在用户友好性上.加了几个progressBar,有显示总进度的.有显示分布进度的..因为程序要跑好几个小时才能执行好,只加个总进度 ...
- alarm函数可以定时
貌似是可以的,不过感觉好像这样用不是很好,最好还是用回timer_settimer一些列函数吧,不过既然开了头,就看下alarm怎么用吧. 1. 所需头文件 #include<unistd.h ...
- emjio表情转json
今天碰到了上传文字给服务端的时候emjio表情转成json就不对了 有大神帮忙解决了,记笔记记笔记--- #import "NSString+EncodedString.h" @i ...
- sql 列设置默认值,语法查询知识点积累
一.修改字段默认值 alter table 表名 drop constraint 约束名字 ------说明:删除表的字段的原有约束 alter table 表名 add constraint 约 ...