Pages

Thursday 22 November 2012

UVA - 11137 - Ingenuous Cubrency

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer("");
        String m = "";
        int coins[] =new int[21];
        for(int i=1;i<22;i++){
            coins[i-1]=i*i*i;
        }
        long arr[] = count(coins, coins.length, 10000);
        while ((m = br.readLine()) != null) {
            int x=Integer.parseInt(m.trim());
            if(x==0)
                  break;
            sb.append(arr[x]).append("\n");
        }
        System.out.print(sb);
    }

    static long[] count(int coins[], int m, int n) {
        long[] temp = new long[n + 1];
        temp[0] = 1;
        for (int i = 0; i < m; i++) {
            for (int j = coins[i]; j < n+1; j++) {
                temp[j] += temp[j - coins[i]];
            }
        }
        return temp;
    }
}

No comments:

Post a Comment