心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
让初始状态直接进入dfs函数。
Here is my code:
#include<iostream>
#include
<string.h>
#define maxn 107
using namespace std;
long s,t,w,counter=0;
char r[maxn],ans[maxn];
bool first,used[maxn];

void dfs(long depth)
{
    
if(counter>=5return;
    
if(depth>=w)
    {
        
if(first)
        {
            first
=false;
            
return;
        }
        cout
<<ans<<endl;
        counter
++;
        
return;
    }
    
for(long i=(first?r[depth]-'a'+1:ans[depth-1]-'a'+2);i<=t;i++)
        
if(!used[i])
        {
            used[i]
=true;
            ans[depth]
=i+'a'-1;
            dfs(depth
+1);
            used[i]
=false;
        }
}

int main()
{
    cin
>>s>>t>>w>>r;
    
//  Input
    memset(ans,0,sizeof(ans));
    memset(used,
false,sizeof(used));
    counter
=0;
    first
=true;
    dfs(
0);
return 0;
}


posted on 2010-09-26 15:40 lee1r 阅读(793) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:递推/递归

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理