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

被折叠的 条评论
为什么被折叠?



