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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. // no of ones
  15. int n=sc.nextInt();
  16.  
  17. // no of zeros
  18. int m=sc.nextInt();
  19.  
  20. int dp[][]=new int[n+m+1][n+1];
  21. dp[0][0]=0;
  22. dp[1][0]=1;
  23. dp[1][1]=1;
  24. for(int i=2;i<=n+m;i++)
  25. {
  26. for(int j=0;j<=n;j++)
  27. {
  28. if(j>0)
  29. dp[i][j]+=dp[i-1][j]+dp[i-1][j-1];
  30. else
  31. dp[i][j]+=dp[i-1][j];
  32. }
  33. }
  34. System.out.println(dp[n+m][n]);
  35. }
  36. }
Success #stdin #stdout 0.15s 56576KB
stdin
2
2
stdout
6