checking cube

package checking_cube; import java.util.Scanner; public class Solution { static int n,count,top; static int lapphuong[]=new int[51]; private static Scanner sc; static void timlapphuong() { for(int i=1;i<=50;i++) { lapphuong[i]=i*i*i; } } static void backtrack(int num, int sum,int pos) { if(num>5 || pos<0) return; if(sum==n) count++; else if(sum<n) { backtrack(num+1,sum+lapphuong[pos],pos); backtrack(num,sum,pos-1); } } public static void main(String[] args) { timlapphuong(); sc = new Scanner(System.in); int T=sc.nextInt(); for(int t=1;t<=T;t++) { n=sc.nextInt(); count=0; for(int i=1;i<=50;i++) if(lapphuong[i]>n) { top=i-1; break; } backtrack(0,0,top); System.out.println("#"+t+" "+count); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.