Advertisement
HXXXXJ

518. Coin Change 2

Sep 15th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1.     public int change(int M, int[] A) {
  2.        
  3.         //dp(x) is to make total x how many possible way
  4.        
  5.         int[] dp = new int[M+1];
  6.         dp[0] = 1;
  7.         for(int c = 0 ; c < A.length; ++c){
  8.             for(int i = A[c]; i < M+1; ++i){
  9.                 dp[i] += dp[i-A[c]];
  10.             }
  11.         }
  12.         return dp[M];
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement