当前位置:网站首页>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 .
边栏推荐
- 【EndNote】文献模板编排语法详解
- B title: razlika priority queue approach
- The second lesson is the construction of development environment
- Mycat2 deploy master-slave MariaDB
- 正则表达式作业
- 2022-024arts: Longest valid bracket
- 2022-024ARTS:最长有效括号
- Problems caused by slivereappbar
- Share high voltage ultra low noise LDO test results
- Beauty naked chat for a while, naked chat over the crematorium!
猜你喜欢

为什么要在时钟输出上预留电容的工位?

B title: razlika priority queue approach
![[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)

我,35岁了。

Take out brother is the biggest support in this society

Bee guitar score high octave and low octave

How to safely delete a useless activity in Android studio

QT note 2

Seq2seq and attention model learning notes

QT note 1
随机推荐
Fluent uses protobuf
NLP (natural language processing) natural language processing learning
Flutter WebView three fingers rush or freeze the screen
Take out brother is the biggest support in this society
Understand microservices bit by bit
Flutter custom player progress bar
2022 national vocational college skills competition "network security" competition question file upload penetration test answer flag
Shell第二天作业
awk作业
23.5 event listeners of application events and listeners
Vscode utility shortcut
The first ide overlord in the universe, replaced...
Kotlin function
Template summary
22-07-14 personal training match 2 competition experience
The data read by Flink Oracle CDC is always null. Do you know
QT note 1
When developing flutter, idea_ ID cannot solve the problem
JS tool function Encyclopedia
Use of room database in kotlin