输入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. ios开发--编码格式

    1.url编码 ios中http请求遇到汉字的时候,需要转化成UTF-8,用到的方法是: NSString * encodingString = [urlString stringByAddingPe ...

  2. ArcGIS Runtime SDK for Android 10.2.5新开发平台安装配置指南

    ArcGIS Runtime SDK for Android 10.2.5版本在年前发布,其中一个重大的变化是:新版本使用了新的开发环境,在10.2.5版本中Esri使用了官方提供的新的Android ...

  3. CentOS防火墙操作实例(启动、停止、开、闭端口)

    注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service   iptables status<回车>   停止防火墙: [root@localh ...

  4. CentOS目录树详细解释

    [sdm_download id=”292″ fancy=”1″] /boot 该目录默认下存放的是Linux的启动文件和内核. initramfs-* 系统启动时的模块供应的主要来源 启动系统所需加 ...

  5. Data Flow ->> Raw File Source & Raw File Destination

    Raw File Source & Raw File Destination一般用在当有某个package在导入数据或者处理数据需要花费非常长的时间的情况下,可以通过把一些处理好的数据先存到r ...

  6. 《c程序设计语言》读书笔记-十六位进制数转十进制

    #include <stdio.h> #include <stdio.h> int htoi(char s[]); main() { char s1[] = "10& ...

  7. 第三篇 从EXCEL电子表格到数据库

    一个靠EXCEL电子表格处理各部门业务数据的公司和一个使用一个统一的数据库存储各个部门用到的业务数据并提供大量权限不同的使用界面给用户的公司两者有什么不同呢?   EXCEL电子表格是数据和操纵数据的 ...

  8. Codeforces Round #206 div1 C

    CF的专业题解 : The problem was to find greatest d, such that ai ≥ d,  ai mod d ≤ k holds for each i. Let ...

  9. Android在OnCreate中获取控件的宽度和高度

    在Android中,有时需要对控件进行测量,得到的控件宽度和高度可以用来做一些计算.在需要自适应屏幕的情况下,这种计算就显得特别重要.另一方便,由于需求的原因,希望一进入界面后,就能得到控件的宽度和高 ...

  10. linux嵌入式系统驱动程序的阻塞与异步

    对于那些需要进程独占的设备,需要使用linux提供的阻塞编程.步骤如下: 1.在设备驱动程序中定义该设备的进程等待列多,并将其初始化 static wait_queue_head_t wait_que ...