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的更多相关文章
随机推荐
- 模拟赛 Problem 3 经营与开发(exploit.cpp/c/pas)
Problem 3 经营与开发(exploit.cpp/c/pas) [题目描述] 4X概念体系,是指在PC战略游戏中一种相当普及和成熟的系统概念,得名自4个同样以“EX”为开头的英语单词. eXpl ...
- Ubuntu 16.04开机进入命令行(tty1)+分辨率调节+字体颜色设置+中文乱码解决(解决虚拟终端Ctrl+Alt+F1分辨率太大)
一.开机进入命令行模式(tty1) sudo vim /etc/default/grub 把GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”改成GRUB_CMDLIN ...
- Eclipse错误出现:Unable to install breakpoint in... (未能解决)
Unable to install breakpoint in... Eclipse Unable to install breakpoint in 的问题还是没解决 1.重装eclipse无效 2 ...
- 【Storage】IBM DS8100开机及配置过程
************************************************************************ ****原文:blog.csdn.net/cla ...
- ARP病毒查找与防范
笔者是一名大学生,学的是网络project. 自然接触的网络就多了.当然免不了做些坏事,嘿嘿. 比如我经经常使用在网上学习的知识去測验一下我自己的电脑或者同学啥的,都是一些小打小闹. 无伤大雅,知道有 ...
- libcurl库进行http通讯-一些主要的函数
这里就简介一下libcurl的一些主要的函数. 调用curl_global_init()初始化libcurl 调用curl_easy_init()函数得到 easy interface型指针 调用cu ...
- Localhost 回环IP 127.0.0.1
LocalHost 127.0.0.1是一个保留地址,用于本地软件測试以及本地进程间通信, 也叫回环IP.回环地址.回送地址(loopback address).不管什么程序,一旦使 用回环IP发送数 ...
- TTS-零基础入门-10分钟教你做一个语音功能
在本片博客正式開始之前,大家先跟我做一个简单的好玩的 小语音. 新建一个文本文档,然后再文档里输入这样 一句话 CreateObject("SAPI.SpVoice").Spea ...
- Codeforces Round #273 (Div. 2)C. Table Decorations 数学
C. Table Decorations You have r red, g green and b blue balloons. To decorate a single table for t ...
- 从基于 SQL 的 CURD 操作转移到基于语义 Web 的 CURD 操作
中文名称 CURD 含义 数据库技术中的缩写词 操作对象 一般的项目开发的各种参数 作用 用于处理数据的基本原子操作 它代表创建(Create).更新(Update).读取(Retrieve) ...