HDU4850 Wow! Such String! —— 字符串构造

本文提供了一道来自HDU在线评测系统的编程题(编号4850)的解决方案。该题使用C++实现,通过动态规划算法解决特定字符串生成问题。代码中包括了必要的头文件引入、全局变量定义、核心算法实现及主函数流程控制。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4850


代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b)  memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 26*26*26*26;
int a[maxn+10];
int vis[26][26][26][26];


void solve()
{
    a[0] = a[1] = a[2] = 0;
    for(int i = 3; i<maxn+3; i++)
    {
        for(int j = 25; j>=0; j--)
        {
            if(vis[a[i-3]][a[i-2]][a[i-1]][j]==0)
            {
                vis[a[i-3]][a[i-2]][a[i-1]][j] = 1;
                a[i] = j;
                break;
            }
        }
    }
}

int main()
{
    int n;
    solve();
    while(scanf("%d",&n)!=EOF)
    {
        if(n>maxn+3)
            printf("Impossible");
        else
            for(int i = 0; i<n; i++)
                printf("%c",a[i]+'a');
        putchar('\n');
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值