Bzoj3297: [usaco2011 open] Forgot

Source: Internet
Author: User
3297: [usaco 128 open] forgottime limit: 10 sec memory limit: MB
Submit: 54 solved: 38
[Submit] [Status] Description

So many times, Bessie has forgotten her cowtube password. However, she remembers some useful information.
First, she remembers that her password (recorded as variable P) is a string of L (1 <= L <= 1,000) and can be divided
One or more words (not necessarily unique) come from the unique word NW (1 <= NW <= 1,000) in the dictionary.
The word w_ I is defined as a lowercase letter sequence of 1 .. 20 ('A'... 'Z ').
She remembers the locations of some letters in her password.
See the following example. Bessie knows that her password looks like "?? L? Ban ??????? "('? 'Represents a letter, which she does not remember ),
Her dictionary contains the following words:

Apple
Cow
Farmer
Banana
Bananas
Pies

Beisi has two possible passwords: "applebananapies" and "applebananascow ".
For your dictionary, find the letter that Bessie remembers. Please find her password. If more than one password is possible, find the first one in the Lexicographic Order.

Input

* Row 1st: two integers separated by spaces: L and NW
* Row 3: A string with the length of L: P
* Row 3rd. N + 2w: Row I + 2 contains the word I in the dictionary: w_ I

Output

 

* Row 3: Password

Sample input15 6
A ?? L? Ban ???????
Apple
Cow
Farmer
Banana
Bananas
Pies

Sample outputapplebananapies
Hint Source

Silver

Question:

At the beginning, I was writing a search, and I found that I couldn't write any more...

This question is actually DP, orz...

          if(check(k+1,j))           {               if(f[j]==""||f[i]>f[k]+s[j])f[i]=f[k]+s[j];           }

I didn't expect the string to be comparable like this, orzzzzzzzzz

Code: (copy)

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<algorithm> 6 #define pa pair<int,int> 7 #define inf 1000000000 8 #define ll long long 9 using namespace std;10 inline int read()11 {12     int x=0;char ch=getchar();13     while(ch<‘0‘||ch>‘9‘)ch=getchar();14     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}15     return x;16 }17 int p,n;18 int l[1005];19 char ch[1005];20 string a[1005],f[1005];21 bool jud(int st,int x)22 {23     for(int i=0;i<l[x];i++)24         if(ch[st+i]!=‘?‘&&ch[st+i]!=a[x][i])return 0;25     return 1;26 }27 int main()28 {29     p=read();n=read();30     scanf("%s",ch+1);31     for(int i=1;i<=n;i++)cin>>a[i];32     for(int i=1;i<=n;i++)l[i]=a[i].size();33     for(int i=1;i<=p;i++)34         for(int j=1;j<=n;j++)35         {36             int t=i-l[j];37             if(t<0)continue;38             if(t!=0&&f[t]=="")continue;39             if(jud(t+1,j))40                 if(f[i]==""||f[i]>f[t]+a[j])f[i]=f[t]+a[j];41         }42     cout<<f[p]<<endl;43     return 0;44 }
View code

 

 

Bzoj3297: [usaco2011 open] Forgot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.