栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1196 Twofive

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1196 Twofive

#include<cstdio>#include<cstring>using namespace std;int f[6][6][6][6][6];char op[9],s[33],out[33];int i,j,n,tmp;bool ok(int x,int t){    return (!out[x]||out[x]==t+'A');}int dfs(int a,int b,int c,int d,int e,int t){    if(t>=25)return 1;    int &tmp=f[a][b][c][d][e];    if(tmp)return tmp;    if(a<5&&ok(a,   t))tmp+=dfs(a+1,b,c,d,e,t+1);    if(b<a&&ok(b+ 5,t))tmp+=dfs(a,b+1,c,d,e,t+1);    if(c<b&&ok(c+10,t))tmp+=dfs(a,b,c+1,d,e,t+1);    if(d<c&&ok(d+15,t))tmp+=dfs(a,b,c,d+1,e,t+1);    if(e<d&&ok(e+20,t))tmp+=dfs(a,b,c,d,e+1,t+1);    return tmp;}int main(){    while(~scanf("%s",op))    {        if(op[0]=='N')        { scanf("%d",&n); for(i=0;i<25;++i)     for(out[i]='A';1;++out[i])     {         memset(f,0,sizeof(f));         tmp=dfs(0,0,0,0,0,0);         if(tmp>=n)break;         n-=tmp;     } puts(out);        }        if(op[0]=='W')        { scanf("%s",s); for(n=i=0;i<25;++i)     for(out[i]='A';out[i]<s[i];++out[i])     {         memset(f,0,sizeof(f));         n+=dfs(0,0,0,0,0,0);     } printf("%dn",n+1);        }    }return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378106.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号