如何计算总没有。用C#字符串可能的组合? [英] How to count total no. of possible combinations of a string using c#?

查看:134
本文介绍了如何计算总没有。用C#字符串可能的组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要解决的算法中,我有这个输入:

I want to solve an algorithm in which I have this input :

N = 30和ST = 1234321

n = 30 and st = 1234321

现在我希望看到使用字符串即多少结合的可形成 它可以有

Now i want to see how many combination's can be formed using the string i.e. it can have

(1 2 3 4 2 1)
  (1 23 4 3 2 1)
  (1 2 3 4 3 21
  ( 12 3 4 3 2 1)
  ( 12 3 4 3 21
  (1 23 4 3 21

(1 2 3 4 2 1)
(1 23 4 3 2 1)
(1 2 3 4 3 21)
(12 3 4 3 2 1)
(12 3 4 3 21)
(1 23 4 3 21)

即。所有小于30。因此,总的组合将是6。

i.e. all less than 30. So total combinations will be 6.

但我们dicard字符串中的计数的时候,我们要么0 present单独或作为领导像09。

But we dicard the string in counts when we have either 0 present alone or as in leading like 09.

取的情况:N = 70和ST = 8675309.现在,在这种情况下,我们有:

take the case: n = 70 and st = 8675309. Now in this case we have:

(8 6 7 5 3 0 9)
  (8 67 5 3 0 9)
  (8 6 7 53 0 9)
  (8 6 7 5 30 9)
  (8 6 7 5 3的 09
  (8 67 53 0 9)
  (8 67 10 30 9)
  (8 67 5 3的 09

(8 6 7 5 3 0 9)
(8 67 5 3 0 9)
(8 6 7 53 0 9)
(8 6 7 5 30 9)
(8 6 7 5 3 09)
(8 67 53 0 9)
(8 67 5 30 9)
(8 67 5 3 09)

在这里数合计为2只(不计,如果我们有任何0 present单独或作为领导像09)。

here count total is 2 only as (we don't count if we have either 0 present alone or as in leading like 09).

请给我建议的C#$ C $下找到这样的组合。

Please suggest me c# code for to find such combinations.

推荐答案

您可以将您的空间模型作为一个二叉树:在 N 个级别,左子加入在 N 和第 N + 1 日列表中的数字,和正确的孩子没有。使用DFS和修剪树枝是非​​法的您的约束,再算上叶节点。

You can model your space as a binary tree: on the nth level, the left child joins the nth and n+1th numbers in the list, and the right child doesn't. Use DFS and prune branches that are illegal by your constraints, then count the leaf nodes.

这篇关于如何计算总没有。用C#字符串可能的组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆