Dyd87
07-02-2010, 17:46
Salve , ho un problema con questo codice
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author Administrator
*/
public class Cube {
/*final int MAX_AMT = 10001;
final int TOT_CNS = 21;*/
public long [] a = new long [10001]; // a[i] is the number of ways of making change for i cents with coins // a[i] is the number of ways of making change for i cents with coins
public int [] d = { 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, // d[i] is the value "i"th coin
1728, 2197, 2744, 3375, 4096, 4913, 5832, 6859, 8000, 9261 };
/**
* @param args the command line arguments
*/
public void FindWays(){
int i, j, coin;
a[0]=1;
for (i=1;i<10000;i++)
a[i]=0;
for (i=0; i<21; i++)
{
coin = d[i];
for (j=coin; j<10001; j++) // It is useless to start with coin > j, so let j=coin
{
a[j] += a[j-coin]; // If you can use the coin, then you can use it or not
}
}
}
public static void main(String[] args) throws IOException {
FindWays();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String cad = "";
while( ((cad = br.readLine()) != null)){
System.out.println(a[Integer.parseInt(cad)]);
}
}
}
Sapreste dirmi perchè in questo punto:
System.out.println(a[Integer.parseInt(cad)]);
Ottengo questo errore?
Non static variable a cannot be reference from a static context?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author Administrator
*/
public class Cube {
/*final int MAX_AMT = 10001;
final int TOT_CNS = 21;*/
public long [] a = new long [10001]; // a[i] is the number of ways of making change for i cents with coins // a[i] is the number of ways of making change for i cents with coins
public int [] d = { 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, // d[i] is the value "i"th coin
1728, 2197, 2744, 3375, 4096, 4913, 5832, 6859, 8000, 9261 };
/**
* @param args the command line arguments
*/
public void FindWays(){
int i, j, coin;
a[0]=1;
for (i=1;i<10000;i++)
a[i]=0;
for (i=0; i<21; i++)
{
coin = d[i];
for (j=coin; j<10001; j++) // It is useless to start with coin > j, so let j=coin
{
a[j] += a[j-coin]; // If you can use the coin, then you can use it or not
}
}
}
public static void main(String[] args) throws IOException {
FindWays();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String cad = "";
while( ((cad = br.readLine()) != null)){
System.out.println(a[Integer.parseInt(cad)]);
}
}
}
Sapreste dirmi perchè in questo punto:
System.out.println(a[Integer.parseInt(cad)]);
Ottengo questo errore?
Non static variable a cannot be reference from a static context?