组合 z
输入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的更多相关文章
- 枚举进行位运算 枚举组合z
枚举进行位运算--枚举组合 public enum MyEnum { MyEnum1 = , //0x1 MyEnum2 = << , //0x2 MyEnum3 = << , ...
- Swift 实现俄罗斯方块详细思路解析(附完整项目)
一:写在开发前 俄罗斯方块,是一款我们小时候都玩过的小游戏,我自己也是看着书上的思路,学着用 Swift 来写这个小游戏,在写这个游戏的过程中,除了一些位置的计算,数据模型和理解 Swift 语言之外 ...
- 【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 ...
- 在数组中找出x+y+z=0的组合
就是找x+y=-z的组合 转化为找出值为-z满足x+y=-z的组合 解法一: 为了查找,首先想到排序,为了后面的二分,nlogn, 然后x+y的组合得n^2的复杂度,加上查找是否为-z,复杂度为nlo ...
- 定义一个类:实现功能可以返回随机的10个数字,随机的10个字母, 随机的10个字母和数字的组合;字母和数字的范围可以指定,类似(1~100)(A~z)
#习题2:定义一个类:实现功能可以返回随机的10个数字,随机的10个字母, #随机的10个字母和数字的组合:字母和数字的范围可以指定 class RandomString(): #随机数选择的范围作为 ...
- bg,fg,ctrl+z组合
使用ctrl + Z 把一个进程挂起 [root@limt ~]# sh Testlsof.sh >111.log ^Z [1]+ Stopped sh Testlsof.sh > 111 ...
- 【BZOJ】2038: [2009国家集训队]小Z的袜子(hose)(组合计数+概率+莫队算法+分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=2038 学了下莫队,挺神的orzzzz 首先推公式的话很简单吧... 看的题解是从http://for ...
- [Linux]在linux中,常常用到ctrl和其他按键组合,常用的有哪些及意义呢
在linux中,常常用到ctrl和其他按键组合,常用的有哪些及意义呢? Ctrl+c 结束正在运行的程序 Ctrl+d 结束输入或退出shell Ctrl+s 暂停屏幕输出[锁住终端] Ctrl+q ...
- [leetcode] 题型整理之排列组合
一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...
随机推荐
- C++:主要几种排序算法及其复杂度
常见排序算法稳定性和复杂度分析快速简记以及转载 分类: 算法 2012-02-07 22:18 399人阅读 评论(1) 收藏 举报 算法mergeshell http://blogold.chin ...
- linux系统主要常见目录结构
linux系统的一切从“/”开始,并按照文件系统目录标准FHS采用树桩结构来存放文件 并定义了每个区域的用途.
- Android 常用时间格式转换代码
/** * 获取现在时间 * * @return 返回时间类型 yyyy-MM-dd HH:mm:ss */ public static Date getNowDate() { Date curren ...
- jsp %EF%BB%BF
utf-8 bom 问题,页面中存在不可忽略的空白,去掉即可 很微妙的一个空格,不易发现
- Highgui.imwrite("/data/pic1111.png", mat)失败,且找不到报错
——> Highgui.imwrite("/data/pic1111.png", mat)失败,且找不到报错. ok -->直接使用以下代码,自己保存mat,从而可以跟 ...
- Angular service
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- Data Base MySQL的常用命令
MySQL的常用命令 一.下载地址: http://www.mysql.com 二.安装注意: root默认密码:123456 三.常用命令: 1.创建用户并授权: 创建用户,只能本地访问:cr ...
- ajax练习四留言板
留言界面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- 【原创】通俗易懂地解决中文乱码问题(2) --- 分析解决Mysql插入移动端表情符报错 ‘incorrect string value: '\xF0...
这篇blog重点在解决问题,如果你对字符编码并不是特别了解,建议先看看 < [原创]通俗易懂地解决中文乱码问题(1) --- 跨平台乱码 >. 当然,如果只是针对解决这个Mysql插入报错 ...
- WCF约束名称的用法
<!--<endpoint address="" binding="basicHttpBinding" bindingConfiguration=& ...