UVa10776 - Determine The Combination(有重复元素的组合问题)

简介: UVa10776 - Determine The Combination(有重复元素的组合问题)
#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cctype>usingnamespacestd;
constintN=26;
strings;
intr;
intcnt[N];
intnumber[N], n;
charch[N];
boolinput();
voidsolve();
voiddfs(intcur, intdep, strings);
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
    }
return0;
}
boolinput()
{
charbuf[N+10];
if (scanf("%s%d", buf, &r) !=2) returnfalse;
s=buf;
sort(s.begin(), s.end());
memset(cnt, 0x00, sizeof(cnt));
for (size_ti=0; i<s.length(); i++) {
cnt[s[i] -'a']++; 
    }
n=0;
for (inti=0; i<N; i++) {
if (cnt[i] !=0) {
number[n] =cnt[i];
ch[n++] =i+'a';
        }
    }
returntrue;
}
voiddfs(intcur, intdep, strings)
{
if (dep==r) {
printf("%s\n", s.c_str());;
return;
    }
for (inti=cur; i<n; i++) {
if (number[i] >0) {
number[i]--;
stringtmp=s;
tmp.append(1, ch[i]);
dfs(i, dep+1, tmp);
number[i]++;
        }
    }
}
voidsolve()
{
dfs(0, 0, "");
}
目录
相关文章
|
9月前
UVa872 - Ordering(拓扑排序)
UVa872 - Ordering(拓扑排序)
42 0
|
7月前
|
开发框架 .NET
poj 3468 A Simple Problem with Integers线段树区间修改
题目意思很简单,有N个数,Q个操作, Q l r 表示查询从l到r 的和,C l r v 表示将从l到r 的值加上v,明显的线段树,不知道线段树的人肯定暴力,肯定超时,哈哈!!
19 0
|
8月前
|
算法
The kth great number(小根堆思想,模板题)
The kth great number(小根堆思想,模板题)
26 0
The kth great number(小根堆思想,模板题)
|
9月前
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
32 0
|
9月前
UVa12478 - Hardest Problem Ever (枚举)
UVa12478 - Hardest Problem Ever (枚举)
30 0
|
Unix Python
LeetCode 71. Simplify Path
给定文件的绝对路径(Unix下的路径)字符串,简化此字符串。
64 0
LeetCode 71. Simplify Path
|
开发者
牛客第六场-Combination of Physics and Maths
题意:选出一个子矩阵,使得所求的压强最大,压强是指这个子矩阵中每个元素之和 / 这个子矩阵最下面一行的元素之和
43 0
牛客第六场-Combination of Physics and Maths
POJ 1306 Combinations
POJ 1306 Combinations
95 0
|
算法
动态规划法(八)最大子数组问题(maximum subarray problem)
问题简介   本文将介绍计算机算法中的经典问题——最大子数组问题(maximum subarray problem)。所谓的最大子数组问题,指的是:给定一个数组A,寻找A的和最大的非空连续子数组。
1736 0