当前位置:网站首页>Alphabetic string
Alphabetic string
2022-07-26 08:30:00 【StephenYYYou】
title : A string of letters
from A,B,C this 3 One letter can make up a lot of strings .
such as :"A","AB","ABC","ABA","AACBB" ....
Now? , Xiao Ming is thinking about a problem :
If there is a limit to the number of letters per letter , How many strings of known length can be formed ?
He asked his good friend to help , And soon I got the code ,
The solution is super simple , The most important part, however, is vague .
Please analyze the source code carefully , Fill in what is missing in the underlined section .
public class A
{
// a individual A,b individual B,c individual C Letter , How many different lengths can be made of n String of .
static 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 ________________________________; // Fill in the blanks
}
public static void main(String[] args)
{
System.out.println(f(1,1,1,2));
System.out.println(f(1,2,3,3));
}
}
For the above test data , The result of Xiaoming's mental arithmetic should be :
6
19
Be careful : Just fill in the missing code in the underlined part , Don't submit anything superfluous or descriptive .
answer : At the first sight of the topic , My first idea is multiple permutations in combinatorics ,
seek r1 individual 1,r2 individual 2,…,rt individual t Number of permutations of , set up r1+r2+…+rt=n,
The number of multiple full permutations is P(n;r1,r2,…,rt).
But in fact, it's complicated to think so , No brain recursion .
title : A string of letters
from A,B,C this 3 One letter can make up a lot of strings .
such as :"A","AB","ABC","ABA","AACBB" ....
Now? , Xiao Ming is thinking about a problem :
If there is a limit to the number of letters per letter , How many strings of known length can be formed ?
He asked his good friend to help , And soon I got the code ,
The solution is super simple , The most important part, however, is vague .
Please analyze the source code carefully , Fill in what is missing in the underlined section .
public class A
{
// a individual A,b individual B,c individual C Letter , How many different lengths can be made of n String of .
static 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 f(a-1,b,c,n-1)+f(a,b-1,c,n-1)+f(a,b,c-1,n-1); // Fill in the blanks
}
public static void main(String[] args)
{
System.out.println(f(1,1,1,2));
System.out.println(f(1,2,3,3));
}
}
For the above test data , The result of Xiaoming's mental arithmetic should be :
6
19
Be careful : Just fill in the missing code in the underlined part , Don't submit anything superfluous or descriptive .
边栏推荐
猜你喜欢

Super nice navigation page (static page)

The most complete network: detailed explanation of six constraints of MySQL

C# 获取选择文件信息
![[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)](/img/25/475c91d7e673fda3930e5a69be0f28.png)
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)

22-07-12 personal training match 1 competition experience

SPSS uses kmeans, two-stage clustering and RFM model to study the behavior law data of borrowers and lenders in P2P network finance

The second lesson is the construction of development environment

shell编程

内存管理-动态分区分配方式模拟

22-07-16 personal training match 3 competition experience
随机推荐
On some concepts involved in journal papers compilation + journal query methods
Exam summary on July 15, 2022
2022-7-9 personal qualifying 6 competition experience
Let's talk about the three core issues of concurrent programming.
23.5 event listeners of application events and listeners
The full name of flitter IDFA is identity for advertisers, that is, advertising identifiers. It is used to mark users. At present, it is most widely used for advertising, personalized recommendation,
2022/7/6 exam summary
Dear teachers, how can sqlserver get DDL in flinkcdc?
宇宙第一 IDE 霸主,换人了。。。
Bee guitar score high octave and low octave
Team members participate in 2022 China multimedia conference
[endnote] compilation of document types and abbreviations of document types
vscode国内的镜像服务器加速
CV learning notes (optical flow)
2022 / 7 / 16 exam summary
Special lecture 2 dynamic planning learning experience (should be updated for a long time)
flink oracle cdc 读取数据一直为null,有大佬知道么
Flutter custom player progress bar
mysql函数汇总之条件判断函数
Function default parameters, arrow functions, and remaining parameters in ES6 - explanation