HDU_1502_dp
Regular Words
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2102 Accepted Submission(s): 825
Let us call the word w regular if the following conditions are satisfied:
A(w)=B(w)=C(w) ;
if c is a prefix of w , then A(c)>= B(c) >= C(c) .
For example, if n = 2 there are 5 regular words: AABBCC , AABCBC , ABABCC , ABACBC and ABCABC .
Regular words in some sense generalize regular brackets sequences (if we consider two-letter alphabet and put similar conditions on regular words, they represent regular brackets sequences).
Given n , find the number of regular words.
Each case contains n (0 <= n <= 60 ).
There is an empty line after each case.
There should be am empty line after each case.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; void add(char A[],char B[],char C[])
{
int a=;
int len1=strlen(A);
int len2=strlen(B);
int wei=;
while(a<len1&&a<len2)
{
int sum=A[a]+B[a]-''-''+wei;
wei=;
if(sum>)
{
wei++;
sum-=;
}
C[a]=sum+'';
a++;
}
while(a<len1)
{
int sum=A[a]+wei-'';
wei=;
if(sum>)
{
wei++;
sum-=;
}
C[a]=sum+'';
a++;
}
while(a<len2)
{
int sum=B[a]+wei-'';
wei=;
if(sum>)
{
wei++;
sum-=;
}
C[a]=sum+'';
a++;
}
if(wei>)
C[a++]='';
C[a]='\0';
} char dp[][][][]; int main()
{
char A[],B[],C[];
for(int i=; i<=; i++)
for(int j=; j<=; j++)
for(int k=; k<=; k++)
strcpy(dp[i][j][k],"");
strcpy(dp[][][],""); for(int i=; i<=; i++)
for(int j=; j<=; j++)
for(int k=; k<=; k++)
{
if(i>=j&&j>=k)
{
add(dp[i-][j][k],dp[i][j-][k],dp[i][j][k]);
add(dp[i][j][k],dp[i][j][k-],dp[i][j][k]);
}
}
int n;
while(scanf("%d",&n)!=EOF)
{
int len=strlen(dp[n][n][n]);
char res[];
for(int i=len-;i>=;i--)
res[len-i-]=dp[n][n][n][i];
res[len]='\0';
printf("%s\n\n",res);
//getchar();
}
return ;
}
HDU_1502_dp的更多相关文章
随机推荐
- Java---15---单例设计模式:---饿汉式和懒汉式
概念: 单例模式确保某个类仅仅有一个实例.并且自行实例化并向整个系统提供这个实例. 单例模式有下面特点: 1.单例类仅仅能有一个实例 2.单例类必须自己给自己创建自己的唯一实例 3.单例类必须给全 ...
- 怎样对Android设备进行网络抓包
问题描写叙述: 前段时间自己的app訪问server的url总是会出现间接性失败的问题,于是和server的同事开了个会.提出了他们server存在的这个bug,我的同事自然说自己的server没问题 ...
- HTTP的GET和POST请求
1.GET请求: 格式例如以下: request-line headers blank-line request-body 如图是我用wireshark截的一个GET请求的HTTP首部: GET请求发 ...
- 6.6 random--伪随机数的生成
本模块提供了生成要求安全度不高的随机数.假设须要更高安全的随机数产生.须要使用os.urandom()或者SystmeRandom模块. random.seed(a=None, version=2) ...
- 谈谈c++纯虚函数的意义!
纯虚函数的存在有什么意义呢?相信大学假设有c++这么课程.在讲到纯虚函数时,必然会讲到纯虚函数是面向接口编程的基础. 如今和大家分享下纯虚函数设计的原由.目的.产生的效果. 现代软件project很庞 ...
- YTU 2715: 函数---判断某年某月某日是这一年中的第几天
2715: 函数---判断某年某月某日是这一年中的第几天 时间限制: 1 Sec 内存限制: 128 MB 提交: 380 解决: 155 题目描述 在主程序(main)中输入某年某月某日,例如2 ...
- Ip获取请求ip
public class IPAdress { public static bool isIP(string str1) { || str1.Length > ) return false; s ...
- Ubuntu 查看当前目录使用的总空间大小
查看当前目录使用的总空间大小 du -h --max-depth=0 #du -h --max-depth=0 217M . 查看当前目录使用总空间的大小以及当前目录下一级文件及文件夹各自使用的总空间 ...
- Tarjan Algorithm
List Tarjan Algorithm List Knowledge 基本知识 基本概念 复杂度 有向图 Code 缩点 Code 用途 无向图 Articulation Point-割顶与连通度 ...
- etcd磁盘清理步骤
etcd默认的空间配额限制为2G,超出空间配额限制就会影响服务,所以需要定期清理 以下是etcd磁盘清理的步骤: 1. 显示空间配额: ETCDCTL_API=3 etcdctl --endpoint ...