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.
timeout due to modulo, can anyone suggest any other way around
staticlong[]table=newlong[60000+1];//max size as given in problemstaticvoidcount(intS[],intm,intn){//long[] table = new long[n + 1];Arrays.fill(table,0);//O(n)table[0]=1;for(inti=0;i<m;i++){for(intj=S[i];j<=n;j++){table[j]+=table[j-S[i]]%(10^9+7);//timeout due to this modulo, if i remove modulo it works fine but will get wrong ans}}//Print all the table value// for (int i = 0; i < table.length; i++) {// System.out.print(" " + table[i]);// }//return (table[n] % 1000000007);}publicstaticvoidmain(String[]args){//Pre calculate all the value till the max range(60000)intnumberOfCoins=60000;int[]coinArray=IntStream.range(1,numberOfCoins+1).toArray();//to fill the array with consecutive numbercount(coinArray,coinArray.length,numberOfCoins);Scannersc=newScanner(System.in);inttestCase=sc.nextInt();for(inti=0;i<testCase;i++){intinput=sc.nextInt();System.out.println(table[input]);}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #78: Coin partitions
You are viewing a single comment's thread. Return to all comments →
timeout due to modulo, can anyone suggest any other way around