【动态规划】bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典

f[i]=min{f[i+1]+1,f[i+len[j]+cant]+cant}(for i=L-1 downto 0)(1<=j<=w)

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int n,m;
string s,words[601];
int f[302];
int main()
{
	scanf("%d%d",&n,&m);
	cin>>s;
	for(int i=1;i<=n;++i) cin>>words[i];
	for(int i=m-1;i>=0;--i)
	  {
	  	f[i]=f[i+1]+1;
	  	for(int j=1;j<=n;++j)
	  	  {
	  	  	int now=0,cant=0;
	  	  	for(int k=i;k<m;++k)
	  	  	  {
	  	  	  	if(words[j][now]==s[k]) ++now;
	  	  	  	else ++cant;
	  	  	  	if(now==words[j].length())
	  	  	  	  break;
	  	  	  }
	  	  	if(now==words[j].length())
	  	  	  f[i]=min(f[i],f[i+cant+now]+cant);
	  	  }
	  }
	cout<<f[0]<<endl;
	return 0;
}
时间: 2024-10-09 13:33:12

【动态规划】bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典的相关文章

BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典

题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 401  Solved: 216[Submit][Status] Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如,贝茜听到有人对她说"browndcodw"

[BZOJ1697][Usaco2007 Feb]Cow Sorting牛排序

1697: [Usaco2007 Feb]Cow Sorting牛排序 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 712  Solved: 416 [Submit][Status][Discuss] Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾气大的牛有可能会捣乱,JOHN想把牛按脾气的大小排序.每一头牛的脾气都是一个在1到100,000之间的整数并且没有两头牛的脾气值相同.

bzoj1633 / P2875 [USACO07FEB]牛的词汇The Cow Lexicon

P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单词的第$k$位可以留下的最多字符数 当该位不选时,就传递上一位的数据$f[i][j][k]=f[i-1][j][k]$ 当该位可以匹配时: $if(a[i]==b[j][k]\&\&f[i-1][j][k-1])$$f[i][j][k]=max(f[i][j][k],f[i-1][j][k-1

[BZOJ] 1631: [Usaco2007 Feb]Cow Party

1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 866  Solved: 624[Submit][Status][Discuss] Description 农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前去X牛棚参加派对还是返回住所,她们都采用了用时最

BZOJ 1631: [Usaco2007 Feb]Cow Party( 最短路 )

这道题和蔡大神出的今年STOI初中组的第二题几乎一模一样... 先跑一遍最短路 , 再把所有边反向 , 再跑一遍 , 所有点两次相加的最大值即为answer ----------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #in

[BZOJ1635][Usaco2007 Jan]Tallest Cow 最高的牛

1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 656  Solved: 402 [Submit][Status][Discuss] Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive inte

1635: [Usaco2007 Jan]Tallest Cow 最高的牛

1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 383  Solved: 211[Submit][Status] Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height

洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon

P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometime

BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are t