zoukankan      html  css  js  c++  java
  • HDOJ-三部曲-1015-The Cow Lexicon

    The Cow Lexicon

    Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
    Total Submission(s) : 16   Accepted Submission(s) : 10
    Problem Description

    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; sometimes they hear words that do not make any sense. For instance, Bessie once received a message that said "browndcodw". As it turns out, the intended message was "browncow" and the two letter "d"s were noise from other parts of the barnyard.

    The cows want you to help them decipher a received message (also containing only characters in the range 'a'..'z') of length L (2 ≤ L ≤ 300) characters that is a bit garbled. In particular, they know that the message has some extra letters, and they want you to determine the smallest number of letters that must be removed to make the message a sequence of words from the dictionary.

     
    Input
    Line 1: Two space-separated integers, respectively: W and L Line 2: L characters (followed by a newline, of course): the received message Lines 3..W+2: The cows' dictionary, one word per line
     
    Output
    Line 1: a single integer that is the smallest number of characters that need to be removed to make the message a sequence of dictionary words.
     
    Sample Input
    6 10 browndcodw cow milk white black brown farmer
     
    Sample Output
    2
     
    Source
    PKU
     
     
    自己的方法把所有的从网上找的测试数据都过了,就是一直WA...最后没办法还是用了别人的方法,看懂了以后自己又凭自己理解敲了一遍,和原作者的代码差不多。。。。。。
     
    状态转移方程dp[i]=min(dp[i+1]+1,dp[i1]+i1-i-len),dp[i]的意思是从第i个到第L个字符需要删除的最少的字符数
    #include<iostream>
    #include<string.h>
    using namespace std;
    int main()
    {
    	int W,L,dp[301],i,j;
    	char word[301],dic[601][301];
    	cin>>W>>L>>word;
    	for(i=0;i<W;i++)
    		cin>>dic[i];
    	dp[L]=0;
    	for(i=L-1;i>=0;i--)
    	{
    		dp[i]=dp[i+1]+1;
    		for(j=0;j<W;j++)         
    		{
    			int len=strlen(dic[j]);
    			if(L-i>=len&&word[i]==dic[j][0])   
    			{
    				int i1=i,i2=0;
    				while(i1<L)
    				{
    					if(dic[j][i2]==word[i1++])
    						i2++;
    					if(i2==len)
    					{
    						dp[i]=min(dp[i],dp[i1]+i1-i-len);
    						break;
    					}
    				}
    			}
    		}
    
    	}
    	cout<<dp[0]<<endl;
    }
    
     
     
  • 相关阅读:
    速达5000出现计算成本数据溢出的问题
    速达软件 移动端 App 功能说明
    无法打开物理文件 操作系统错误 5: 5(拒绝访问。) 问题解决
    速达软件开发版使用技巧-销售开单单据打印格式设计
    开发版速达软件如何进行有效授权
    速达软件 移动端 App 下载试用
    速达软件二次开发-试用版本下载,欢迎合作
    速达软件开发版使用技巧-每页固定行样式报表设计
    Cause: org.postgresql.util.PSQLException: 栏位索引超过许可范围:13,栏位数:12
    springboot 开启事务回滚
  • 原文地址:https://www.cnblogs.com/aljxy/p/3315660.html
Copyright © 2011-2022 走看看