Learn about best book for permutation and combination, we have the largest and most updated best book for permutation and combination information on alibabacloud.com
Give you a 40 catty of watermelon, to 3 people, how many kinds of sub-method? I implemented it in PHP with the following code$aa=Range(1,40);$BB=Array();foreach($aa as $k=$val){ foreach($aa as $v){ foreach($aa as $VL){ $sum=$val+$v+$VL; if($sum= = 40){ $BB[$k][0] =$val; $BB[$k][1] =$v; $BB[$k][2] =$VL; } } }}Echo' ;Print_r($BB);Exit;Results:Array ( [0] = = Array ( [0] = 1 [1] = [2] = 1 ) [1] = =
algorithm title: There are 1, 2, 3, 4 numbers, can be composed of how many different and no repetition of the number of three digits? How much are they?Program Analysis: can be filled in hundreds, 10 digits, single digit numbers are 1, 2, 3, 4. Make all the permutations and then remove the permutations that do not meet the criteria.Program Source code:1 for in range (1,5):2for in range (1,5):3 for in range (1,5):4 if and and (j! = k):5 print i,j,kThe
Title Link: http://lightoj.com/volume_showproblem.php?problem=1005Test instructions is in a n*n square put K chess pieces, each row each column can not have two pieces, ask how many methods, and 8 queen question very much like, but 8 queen problem can use violent search, but the value range of the subject n is large, can not use search; I found the formula at the game, However, due to the multiplication order problem caused by the error, is A (n,k) *a (n,k)/A (k,k), i.e. C (n, k) *a (n, k);#incl
Test instructions: ...Analysis: Every time there are three kinds of methods, three-3^n, the root pillar, so is the second party.The code is as follows:#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include HDU 1996 Norwood VI (permutation combination)
Reproduced in panda: http://blog.csdn.net/qq_32734731/article/details/514847291#include 2#include 3#include 4#include 5#include 6#include string>7#include 8 using namespacestd;9 Long LongMod=1000000007;Ten Long LongQpow (Long LongXLong Longk) One { A Long Longres=1; - while(k) - { the if(K 1) -res=res*x%MoD; -x=x*x%MoD; -k>>=1; + } - returnRes; + } A Long LongInvLong LongALong Longx) at { - returnQpow (a,x-2); - } - intllintXinty) - { - Long Longt1=1, t2=1; i
Links: http://lightoj.com/volume_showproblem.php?problem=11321132-summing up Powers
PDF (中文版)
Statistics
Forum
Time Limit: 2 second (s)
Memory Limit: MB
Given N and K, you had to find(1K + 2K + 3K + ... + NK)% 232InputInput starts with an integer T (≤200), denoting the number of test cases.Each case contains the integers N (1≤n≤1015) and K (0≤k≤50) in a.OutputFor each case, print the case number and the result.
notes fall would be very high. And the game would be more exciting. There is a lot of cows who play this game very well. If you had a chance to watch them playing, you would say ' Orz 'From your heart. But as a programmer, we would admire people the WHO write this game more. Here comes the problem.If you is assigned write a game similar to this game. If there is n different sound tracks and M different notes. How many different ways can-arrange the notes to fall.InputThere is multiple test case
Topic Links:http://acm.hdu.edu.cn/showproblem.php?pid=5194Main topic:There are n black balls and M white balls in the bag. Using 1 means that the black ball is taken out, 0 means that the white ball is taken out. Not put backN+m a ball out of the bag. Ask for the next two balls to be taken out of the first ball white ball, the second ball is the expectation of black ballNumber of times, i.e. what is the expected number of "01" occurrences.Ideas:Consider the expected additive. The probability of
that meet the requirements is output. Each output occupies one row.Sample Input 24 Sample output 117 Authoreddy idea: If you want to find the total number of types, you can select the plug-in method. There are n numbers in total, and m numbers (n> = m> = 2) are selected from them, which is equivalent to inserting boards in the M number. In total, there is a possibility of making one, from the extraction of N in the total number, M is equal to CNM = N in the
position
**********
Just select the I-1 snowballs on the left and meet the requirement that is DP [I-1], the rest of the n-I balls casually put (n-I )! * 2 ^ (n-I) method, so the number of methods DP [I-1] * C [n-1] [I-1] * (N-I )! * 2 ^ (n-I)
Therefore, the total number of winning Methods DP [N] = sum {DP [I-1] * C [n-1] [I-1] * (N-I )! * 2 ^ (n-I)} 1
Reduction: DP [N] = sum {DP [I-1] * (n-1 )! * 2 ^ (n-I)/(I-1 )! } 1
That is, DP [N] = (n-1 )! * (DP [0] * 2 ^ (n-1)/0! + Dp [1]
Title: Given 1-n numbers, permutations and combinations.Solution: Recursive. The first number has n choices, the second number has a n-1 selection, and the output is recursively arranged sequentially. Use an array to represent n digits, and use the number 0.Implementation language: C + +#include Output:text/Shing original Reprint please indicate the source http://blog.csdn.net/yxstars/article/details/41516105Algorithm: C + + permutation
Total submissions:18112
Accepted:5514
DescriptionIn how many ways can you choose k elements out of n elements, not taking order into account?
Write a program to compute this number.
InputThe input will contain in one or more test cases.
Each test case consists of one line containing two integers n (n> = 1) and K (0 Input is terminated by two zeroes for N and K.
OutputFor each test case, print one line containing the required number. This number will always fit into an inte
Full Permutation and combination of common algorithms
The full sorting algorithm is a common algorithm, and its practices are also diverse.
First, let's take A look at the most intuitive thinking. The idea is as follows: if there are no repeated elements, input an array A and insert it into another array B, if B already contains this element, skip this step; otherwise, insert array B. Let's take a look at t
To do this problem, think of whether it is DP, and then found that DP can do, but has been the pit to death.enumerate the last merged position, and then for the minus, the two parts of the divided into a different combination of methods,(A1+a2 ...) + (B1,b2 ............) For each A, the number of the added B factorial times, for each B, plus a number of factorial timessubtraction in the same veina special point of multiplication(A1+a2 ...) * (B1,B2) *
After study, we can find that each person's contribution is C (n-2,k-1) +c (n-3,k-1) ... C (k-1,k-1)Also note that the plus sign is all on the left.A template for O (n) preprocessing O (1) combination numbers is also used here. It's wonderful. Wonderful...1#include 2#include 3#include 4 #defineLL Long Long5 6 using namespacestd;7 8 Const intMOD = 1e9+7;9 Const intMAXN = 3e5+Ten;Ten One LL F[MAXN],INV[MAXN],FAC[MAXN]; A - voidInit () - { thefac[0] =
Permutation and combinatorial algorithms are common algorithms for examining recursion, and these two algorithms can be implemented in a recursive and concise way.
After many groping and thinking, I summarize the following for reference.
The program code is as follows:
#include
Run Result:
Perm ():
abcd abdc acbd acdb adbc
adcb bacd badc Bcad BCDA BDCA cabd cadb cbad cbda cdab cdba dabc dacb Dbac DBCA dcab DCBA
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.