fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. static long[][][] dp=new long[11][82][11];
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. // your code goes here
  15. Scanner sc=new Scanner(System.in);
  16.  
  17. //single digit number mera base case hoyega,1 to 9
  18. for(int x=0;x<9;x++){
  19. dp[1][x][x]=1;
  20. }
  21. for (int i = 2; i <= 10; i++) {
  22. for (int j = 0; j <= 81; j++) {
  23. for (int k = 0; k <= 9; k++) {
  24. if (j - k >= 0) {
  25. long p = 0;
  26. for (int number = 0; number <= 9; number++) {
  27. p += dp[i - 1][j - k][number];
  28. }
  29. dp[i][j][k] = p;
  30. }
  31. }
  32. }
  33. }
  34. long res = 0;
  35. for (int x = 1; x <= 9; x++) {
  36. res += dp[5][8][x];
  37. }
  38.  
  39. System.out.println("count of 5 digit num with digi sum as 8: " + res);
  40.  
  41. }
  42. }
Success #stdin #stdout 0.16s 56892KB
stdin
Standard input is empty
stdout
count of 5 digit num with digi sum as 8: 330