Blue Bridge Cup Daily One Question 1.7 2017 Provincial Competition Group A 5. Letter string [code fill in the blank][DP][permutation and combination problem]

Title description

  2017 Blue Bridge Cup Software Provincial Competition C++ University Group A Question 5 " Letter Strings ".
  A code fill-in-the-blank question. It is said that this is a traditional question of giving points, let's take a look at how to give points.
  Because it's not difficult, I won't bother Ni Wendi, and Teacher Luo can do it himself.


Many strings can be formed by the three letters A, B, and C.
For example: "A", "AB", "ABC", "ABA", "AACBB"…

Now, Xiao Ming is thinking about a question:
If the number of each letter is limited, how many strings of known length can be formed?

He asked a good friend to help, and quickly got the code. The
solution was super simple, but the most important part was unclear.

Please carefully analyze the source code and fill in the missing content in the underlined part.

#include <stdio.h>

// a个A,b个B,c个C 字母,能组成多少个不同的长度为n的串。
int f(int a, int b, int c, int n)
{
	if(a<0 || b<0 || c<0) return 0;
	if(n==0) return 1; 
	
	return ______________________________________ ;  // 填空
}

int main()
{
	printf("%d\n", f(1,1,1,2));
	printf("%d\n", f(1,2,3,3));
	return 0;
}

For the above test data, the result of Xiaoming's oral calculation should be:
6
19
Note: Only fill in the missing code in the underlined part, and do not submit any redundant content or explanatory text.

https://blog.csdn.net/weixin_43914593/article/details/112297807

A waste does not feel that it is a QAQ

return f(a - 1, b, c, n - 1) + f(a, b - 1, c, n - 1) + f(a, b, c - 1, n - 1)

Classical Solution of Permutation and Combination Problem——Generating Function

Guess you like

Origin blog.csdn.net/qq_43660826/article/details/112983095