We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/* * 2024 ^_^ *ThinhNguyen97 * */importjava.math.BigInteger;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.Collections;importjava.util.Comparator;importjava.util.HashMap;importjava.util.Set;importjava.util.HashSet;importjava.util.LinkedList;importjava.util.List;importjava.util.Map;importjava.util.Queue;importjava.util.Scanner;importjava.util.Stack;publicclassSolve_problems{staticintn;//so luong dong xustaticint[]coins=newint[1001];//luu menh gia cac dong xustaticlong[]dp=newlong[1000001];staticlongsolve(intS){dp[0]=1;//so tien la 0 tuc la co 1 cach lua chonfor(intj=0;j<n;j++)//duyet het mangfor(inti=coins[j];i<=S;i++){dp[i]+=dp[i-coins[j]];//dp[i]%=1000000007;}returndp[S];}publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);////////intS=sc.nextInt();//so tien can tao ran=sc.nextInt();for(inti=0;i<n;i++)coins[i]=sc.nextInt();System.out.println(solve(S));// Close the Scanner instancesc.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
DP: Coin Change
You are viewing a single comment's thread. Return to all comments →