输入a b c d e以及它们对应的数字
比如
a-->1 2 3 
b-->2 3
c-->1
d-->3 4 5
e-->1 3 5
输出a b c d e的可用组合,a b c d e不重复,如
a-->2
b-->3
c-->1
d-->4
e-->5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var dict = new Dictionary<char, List<int>>()
{
{ 'a', new List<int> { 1, 2, 3 } },
{ 'b', new List<int> { 2, 3 } },
{ 'c', new List<int> { 1 } },
{ 'd', new List<int> { 3, 4, 5 } },
{ 'e', new List<int> { 1, 3, 5 } }
};
foo(dict, new Dictionary<char, int>());
} static void foo(Dictionary<char, List<int>> data, Dictionary<char, int> pre)
{
if (data.Count == 0)
{
Console.WriteLine("found:");
foreach (var item in pre.OrderBy(x => x.Key))
Console.WriteLine("{0} - {1}", item.Key, item.Value);
return;
}
var first = data.OrderBy(x => x.Value.Count()).First();
foreach (var item in first.Value)
{
foo(data.OrderBy(x => x.Value.Count()).Skip(1).ToDictionary(x => x.Key, x => x.Value.Except(new int[] { item }).ToList()), pre.Cast<KeyValuePair<char, int>>().Concat(new KeyValuePair<char, int>[] { new KeyValuePair<char, int>(first.Key, item) }).ToDictionary(x => x.Key, x => x.Value));
}
}
}
}

组合 z的更多相关文章

  1. 枚举进行位运算 枚举组合z

    枚举进行位运算--枚举组合 public enum MyEnum { MyEnum1 = , //0x1 MyEnum2 = << , //0x2 MyEnum3 = << , ...

  2. Swift 实现俄罗斯方块详细思路解析(附完整项目)

    一:写在开发前 俄罗斯方块,是一款我们小时候都玩过的小游戏,我自己也是看着书上的思路,学着用 Swift 来写这个小游戏,在写这个游戏的过程中,除了一些位置的计算,数据模型和理解 Swift 语言之外 ...

  3. 【Python】使用torrentParser1.03对多文件torrent的分析结果

    Your environment has been set up for using Node.js 8.5.0 (x64) and npm. C:\Users\horn1>cd C:\User ...

  4. 在数组中找出x+y+z=0的组合

    就是找x+y=-z的组合 转化为找出值为-z满足x+y=-z的组合 解法一: 为了查找,首先想到排序,为了后面的二分,nlogn, 然后x+y的组合得n^2的复杂度,加上查找是否为-z,复杂度为nlo ...

  5. 定义一个类:实现功能可以返回随机的10个数字,随机的10个字母, 随机的10个字母和数字的组合;字母和数字的范围可以指定,类似(1~100)(A~z)

    #习题2:定义一个类:实现功能可以返回随机的10个数字,随机的10个字母, #随机的10个字母和数字的组合:字母和数字的范围可以指定 class RandomString(): #随机数选择的范围作为 ...

  6. bg,fg,ctrl+z组合

    使用ctrl + Z 把一个进程挂起 [root@limt ~]# sh Testlsof.sh >111.log ^Z [1]+ Stopped sh Testlsof.sh > 111 ...

  7. 【BZOJ】2038: [2009国家集训队]小Z的袜子(hose)(组合计数+概率+莫队算法+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2038 学了下莫队,挺神的orzzzz 首先推公式的话很简单吧... 看的题解是从http://for ...

  8. [Linux]在linux中,常常用到ctrl和其他按键组合,常用的有哪些及意义呢

    在linux中,常常用到ctrl和其他按键组合,常用的有哪些及意义呢? Ctrl+c 结束正在运行的程序 Ctrl+d 结束输入或退出shell Ctrl+s 暂停屏幕输出[锁住终端] Ctrl+q ...

  9. [leetcode] 题型整理之排列组合

    一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...

随机推荐

  1. Struts2笔记——与ServletAPI解耦

    与ServletAPI解耦的访问方式 为了避免与 Servlet API 耦合在一起, 方便 Action 做单元测试, Struts2 对 HttpServletRequest, HttpSessi ...

  2. Union的妙用和注意

    对于Union我用的比较少,最近一段时间大多使用Lua,所以复习一下Union Union是共用体,顾名思义,公用一块内存 一块内存不同的访问方式 // 1.数组的便捷访问 // 一块内存两种等价的访 ...

  3. z-index无效问题的解决方法

    在使用z-index这个属性之前,我们必须先了解使用z-index的必要条件: 1.要想给元素设置z-index样式,必须先让它变成定位元素,说的明白一点,就是要给元素设置一个postion:rela ...

  4. google protobuf使用

    下载的是github上的:https://github.com/google/protobuf If you get the source from github, you need to gener ...

  5. shell中的大括号和小括号

      1.shell中的大括号和小括号   1.${var} 2.$(cmd) 3.() 和 {} 4.${var:-string}, ${var:+string},  ${var:=string}, ...

  6. jenkins-slave的搭建和使用

    一 什么是Jenkins的分布式构建和部署 Jenkins的分布式构建,在Jenkins的配置中叫做节点,分布式构建能够让同一套代码或项目在不同的环境(如:Windows和Linux系统)中编译.部署 ...

  7. [2014-03-13 08:46:42 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

    Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. 问题提示 ...

  8. SQL高性能查询优化语句

    1.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num is null可以在num上设置 ...

  9. 手持机连不上信道设置为13的AP

    这个是正常的, 因为每个国家的CHANNEL 都不一样, 中国和美国都只支持 CHANNEL 1- 11  欧洲会到 12, 13 channal , 日本会到CHANNEL 14 . "O ...

  10. ViewState压缩技术

    ViewState 的使用,大家可以说是又爱又恨,它其中一个特性就是保存页面的状态,对于只是展示的页面,我们可以直接在页面文件中使用 EnableViewState="false" ...