+ 1

How to solve this in Java?

There are suppose N number of houses on a lane which are to be painted and the colours available are C. Some houses are to be painted with the same colour as their adjacent houses and some a different from their adjacent. It is decided to paint K pairs of houses with a different colour. The task here is to find the number of ways to paint N houses with C differenr colours such that exactly K pairs of adjacent houses are painted with different colours. If the houses could not be painted in a given combination K then print 0. Example:N=4;C=2;K=1 Output:6 Suppose the colours are 1 and 2 then 1 1 1 2 1 1 2 2 1 2 2 2 2 2 1 1 2 1 1 1 2 2 2 1

10th Oct 2021, 8:12 AM
Mohammad Abdullah
Mohammad Abdullah - avatar
4 odpowiedzi
+ 2
You could use this mixing method to solve your task however that is: https://code.sololearn.com/cU940wV7ag71/?ref=app
10th Oct 2021, 1:49 PM
JaScript
JaScript - avatar
+ 1
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Number of Houses:"); int n=sc.nextInt(); System.out.println("Number of Colours:"); int c=sc.nextInt(); System.out.println("Number of Combinations:"); int k=sc.nextInt(); } only this much
10th Oct 2021, 8:35 AM
Mohammad Abdullah
Mohammad Abdullah - avatar
+ 1
I think of double dimensional array
10th Oct 2021, 8:35 AM
Mohammad Abdullah
Mohammad Abdullah - avatar
0
Your attempt?
10th Oct 2021, 8:34 AM
Eashan Morajkar
Eashan Morajkar - avatar