代码规范检查

本文探讨了代码规范的重要性,并通过解决全排列、Word Maze和最小公倍数问题,深入讲解了深度优先搜索在图论中的应用。
摘要由CSDN通过智能技术生成

30:字符串重排

// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
int ans=0;
static int cmp(const void *a, const void *b)
{
   
    return *(char*)a - *(char*)b;
}
static void dfs(int idx, int *vis, int sum, int len, char *str)
{
   
    if (sum == len)
    {
   
        ans++;
        return;
    }
    for (int i = 0; i < len; i++)
    {
   
        if (i > 0 && str[i] == str[i-1] && !vis[i-1]) {
   
            continue; // "同一层" 相同的跳过
        }
        if (!vis[i]) {
   
            vis[i] = 1;
            dfs(idx+1, vis, sum+1, len, str);
            vis[i] = 0;
        }
    }
}
int main()
{
   
    // please define the C input here. For example: int n; scanf("%d",&n);
    // please finish the function body here. 
    // please define the C output here. For example: printf("%d\n",a);  
    int len = 0;
    char str[11] = {
   0};
    scanf("%s", str);
    len = strlen(str);
    qsort(str, len, sizeof(char), cmp);
    int vis[11] = {
   0};
    dfs(0, vis, 0, len, str);
    printf("%d", ans);
    return 0;
}

46.全排列

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值