2272: [Usaco2011 Feb]Cowlphabet 奶牛文字
2272: [Usaco2011 Feb]Cowlphabet 奶牛文字
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 138 Solved: 97
[Submit][Status][Discuss]
Description
Like all bovines, Farmer John's cows speak the peculiar 'Cow'
language. Like so many languages, each word in this language comprises
a sequence of upper and lowercase letters (A-Z and a-z). A word
is valid if and only if each ordered pair of adjacent letters in
the word is a valid pair.
Farmer John, ever worried that his cows are plotting against him,
recently tried to eavesdrop on their conversation. He overheard one
word before the cows noticed his presence. The Cow language is
spoken so quickly, and its sounds are so strange, that all that
Farmer John was able to perceive was the total number of uppercase
letters, U (1 <= U <= 250) and the total number of lowercase
letters, L (1 <= L <= 250) in the word.
Farmer John knows all P (1 <= P <= 200) valid ordered pairs of
adjacent letters. He wishes to know how many different valid
words are consistent with his limited data. However, since
this number may be very large, he only needs the value modulo
97654321.
Input
* Line 1: Three space-separated integers: U, L and P
* Lines 2..P+1: Two letters (each of which may be uppercase or
lowercase), representing one valid ordered pair of adjacent
letters in Cow.
第一行:三个用空格隔开的整数:U,L和P,1≤U.L≤250,1≤P<=200
第二行到P+1行:第i+l有两个字母,表示第i个词素,没有两个词素是完全相同的
Output
* Line 1: A single integer, the number of valid words consistent with
Farmer John's data mod 97654321.
单个整数,表示符合条件的单词数量除以97654321的余数
Sample Input
AB
ab
BA
ba
Aa
Bb
bB
INPUT DETAILS:
The word Farmer John overheard had 2 uppercase and 2 lowercase
letters. The valid pairs of adjacent letters are AB, ab, BA, ba,
Aa, Bb and bB.
Sample Output
HINT
(可能的单词为AabB, Abba, abBA, BAab,BbBb, bBAa, bBbB)
Source
题解:萌萌哒动规。。。f[i,j,k]表示已经有了i个字母,其中j个是大写的(你要愿意的话弄成小写的也没关系),k表示最后一个字符(注意:大小写不等同!!!故1<=k<=52),这样子的复杂度为O(52(U+L)U),完全可以
(PS:我在想如果出数据的人比较良心的话,万一弄一大堆数据L=0的该怎么办QAQ,更可怕的是万一再弄一大堆U=0的。。。那样子的话如果再加强U、L的话,就能轻松让大部分程序TLE了呵呵,不过这道题里面就算是O(52(U+L)^2)也完全能过,不怕)
const q=;
type
point=^node;
node=record
g:longint;
next:point;
end;
var
i,j,k,l,m,n:longint;
b:array[..,..] of longint;
c:array[..,..,..] of longint;
a:array[..] of point;
c1,c2:char;p:point;
function callback(ch:char):longint;inline;
begin
if ch>='a' then exit(ord(ch)-ord('a')+) else exit(ord(ch)-ord('A')+);
end;
procedure add(x,y:longint);inline;
var p:point;
begin
new(p);p^.g:=y;
p^.next:=a[x];a[x]:=p;
end;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end; begin
readln(n,m,l);
for i:= to do a[i]:=nil;
fillchar(c,sizeof(c),);
for i:= to l do
begin
readln(c1,c2);
b[i,]:=callback(c1);
b[i,]:=callback(c2);
add(b[i,],b[i,]);
if b[i,]> then c[,,b[i,]]:= else c[,,b[i,]]:=;
end;
for i:= to n+m do
for j:= to min(n,i) do
for k:= to do
begin
p:=a[k];
while p<>nil do
begin
if k> then
begin
if j> then c[i,j,k]:=(c[i,j,k]+c[i-,j-,p^.g]) mod q;
end
else
c[i,j,k]:=(c[i,j,k]+c[i-,j,p^.g]) mod q;
p:=p^.next;
end;
end;
l:=;
for i:= to do l:=(l+c[n+m,n,i]) mod q;
writeln(l);
end.
2272: [Usaco2011 Feb]Cowlphabet 奶牛文字的更多相关文章
- 【bzoj2272】[Usaco2011 Feb]Cowlphabet 奶牛文字 dp
题目描述 Like all bovines, Farmer John's cows speak the peculiar 'Cow'language. Like so many languages, ...
- BZOJ2272: [Usaco2011 Feb]Cowlphabet 奶牛文字
n<=250个大写字母和m<=250个小写字母,给p<=200个合法相邻字母,求用这些合法相邻字母的规则和n+m个字母能合成多少合法串,答案mod 97654321. 什么鬼膜数.. ...
- 【BZOJ】【3301】【USACO2011 Feb】Cow Line
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...
- BZOJ2274: [Usaco2011 Feb]Generic Cow Protests
2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 196 Solve ...
- BZOJ3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 67 Solved: 39[Submit ...
- BZOJ3300: [USACO2011 Feb]Best Parenthesis
3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 89 Solved: 42 ...
- 3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 82 Solved: 49[Submit ...
- 【USACO2002 Feb】奶牛自行车队
[USACO2002 Feb]奶牛自行车队 Time Limit: 1000 ms Memory Limit: 131072 KBytes Description N 头奶牛组队参加自行车赛.车队在比 ...
- BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟
Description Recently, the cows have been competing with strings of balanced parentheses and compari ...
随机推荐
- Linux笔记(五) - 用户管理命令
(1)添加用户:useradd [选项] 用户 -u UID:手工指定用户的UID号-d 家目录:手工指定用户的家目录-c 用户说明:手工指定用户说明,有空格需加双引号-g 初始组:手工指定初始组-G ...
- 纯CSS3实现不错的表单验证效果
这是补充HTML5基础知识的系列内容,其他为: 一.HTML5-- 新的结构元素 二.HTML5-- figure.time.details.mark 三.HTML5-- details活学活用 四. ...
- Ajax+存储过程真分页实例解析(10W数据毫秒级+项目解析)
周末闲来无事,突然想写个分页的东西玩玩,说走就走 在文章最后我会把整个项目+数据库附上,下载下来直接运行就可以看效果了.整个项目采用的是简单三层模式,开发平开是VS2010+SQL2012 一.我要做 ...
- windows下Visual Studio Code 1.9安装
点击送你去官网下载vs code 进入下载页面如下 下载完成双击安装 安装完成打开之后如下图,最新版的默认中文就挺好的! 注意下面是微软建议: Note: .NET Framework 4.5.2 i ...
- 《JAVASCRIPT高级程序设计》Ajax与Comet
Ajax,是Asynchronous JavaScript + XML的简写,这一技术能向服务器请求额外的技术而无需卸载页面,会带给用户更好的体验.Ajax的核心是XMLHttpRequest对象.为 ...
- 源码(09) -- java.util.Arrays
java.util.Arrays 源码分析 ------------------------------------------------------------------------------ ...
- PLSQL DEVELOPER 使用的一些技巧【转】
1.登录后默认自动选中My Objects 默认情况下,PLSQL Developer登录后,Brower里会选择All objects,如果你登录的用户是dba,要展开tables目录,正常情况都需 ...
- 如何增强ArcGIS插值图出图效果
如何增强ArcGIS插值图出图效果 by 李远祥 在一些科研领域,经常会遇到使用插值的方式进行处理,并生成最终的插值图.插值图在ArcGIS里面非常容易生成,只要具备了采用点数据,通过ArcToolB ...
- 一篇文章搞定css3 3d效果
css3 3d学习心得 卡片反转 魔方 banner图 首先我们要学习好css3 3d一定要有一定的立体感 通过这个图片应该清楚的了解到了x轴 y轴 z轴是什么概念了. 首先先给大家看一个小例子: 卡 ...
- React核心内容归纳总结
状态.属性.组件API.组件的生命周期 当react的状态改变时,自动执行this.render()方法更新组件ES6写React的时候,事件里不会自动绑定this,需要自己绑定,或者直接在const ...