public static void main(String[] args) {
//give N, find the number of different ways to write N as the sum of 1, 3, 4
// 1. subproblem; 2. relation; 3. the begin data
// 1. d[n]: n value and the ways d[n]
// 2. d[n] = d[n-1] + d[n-3] + d[n-4]
// 3. d[0],d[1],d[2],d[3]
int n = 5;
if (n <= 3 && n >= 0) {
switch (n) {
case 0:
System.out.println("Ways: "+1);
break;
case 1:
System.out.println("Ways: "+1);
break;
case 2:
System.out.println("Ways: "+1);
break;
case 3:
System.out.println("Ways: "+2);
break;
default:
break;
}
} else if (n >= 4) {
//core
int[] ways = new int[n+1];
ways[0]=1;ways[1]=1;ways[2]=1;ways[3]=2;
for (int i = 4; i <= n; i++) {
ways[i] = ways[i-1] + ways[i-3] + ways[i-4];
}
System.out.println("Ways: " + ways[n]);
} else {
System.out.println("N should be >= 0!");
}
}