HYSBZ - 1055 玩具取名 (十分暴力的DP)

题目描述:

点击打开链接

中文题不解释题意,这题DP可以说是十分暴力的,先把所有可以压缩的情况预处理好,然后对于每个区间直接暴力枚举每种情况,注意用|运算,这样只要有一种情况符合要求就会记为1,最后检验一下四种情况是否可以即可。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<string>
#include<cmath>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXM=200;
const long long MOD=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1);
struct pt
{
    char ch1,ch2;
    char ch;
};

int W,I,N,G;
string s;
struct pt p[210];
bool dp[210][210][210];

int main()
{
        scanf("%d%d%d%d",&W,&I,&N,&G);
        int cnt=1;
        for (int i=1;i<=W;i++)
        {
            cin>>s;
            p[cnt].ch1=s[0];p[cnt].ch2=s[1];p[cnt].ch='W';
            cnt++;
        }
        for (int i=1;i<=I;i++)
        {
            cin>>s;
            p[cnt].ch1=s[0];p[cnt].ch2=s[1];p[cnt].ch='I';
            cnt++;
        }
        for (int i=1;i<=N;i++)
        {
            cin>>s;
            p[cnt].ch1=s[0];p[cnt].ch2=s[1];p[cnt].ch='N';
            cnt++;
        }
        for (int i=1;i<=G;i++)
        {
            cin>>s;
            p[cnt].ch1=s[0];p[cnt].ch2=s[1];p[cnt].ch='G';
            cnt++;
        }
        cin>>s;
        int len=s.size();
        memset(dp,false,sizeof(dp));
        for (int i=0;i<len;i++)
            dp[i][i][s[i]]=true;
        for (int i=1;i<len;i++)
        {
            for (int j=0;j+i<len;j++)
            {
                for (int k=j;k<=j+i;k++)
                    for (int l=1;l<cnt;l++)
                    dp[j][j+i][p[l].ch]|=(dp[j][k][p[l].ch1]&&dp[k+1][i+j][p[l].ch2]);
            }
        }

        bool flag=false;
        if (dp[0][len-1]['W']) cout<<'W',flag=true;
        if (dp[0][len-1]['I']) cout<<'I',flag=true;
        if (dp[0][len-1]['N']) cout<<'N',flag=true;
        if (dp[0][len-1]['G']) cout<<'G',flag=true;
        if (!flag) cout<<"The name is wrong!"<<endl;
        else cout<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值