1.
/** * FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* * Problem: 147 - Dollars
* * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=83
* * Savkina Ekaterina
* * @version 1.0, 06/17/2010
* *Method : Ad-Hoc
* * Status : Accepted
* * Runtime: 1.636 */
package dollars;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static int[] coins = { 10000, 5000, 2000, 1000, 500, 200, 100, 50,
20, 10, 5 };
public static void main(String... args) {
Scanner sc = new Scanner(System.in);
int v = 11;
long mway[] = new long[30000 + 1];
mway[0] = 1;
for (int i = 0; i < v; i++) {
int c = coins[i];
for (int j = c; j <= 30000; j++) {
mway[j] += mway[j - c];
}
}
DecimalFormat f = new DecimalFormat("#0.00");
while (true) {
int money = (int) (sc.nextDouble() * 100 + 0.5);
if (money == 0)
break;
System.out.printf("%6.2f%17d\n", money / 100.0, mway[money]);
}
return;
}
}
2.
package acm_147_dollars;
import java.util.Scanner;
/**
* FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: acm_147_dollars
* Link:
*
* @author Martin Lambeck
* @version 1.0, 01.09.2010
*
* Method : dp
* Status : Accepted
* Runtime: 1.316
*/
public class Main
{
static Scanner sc = new Scanner(System.in);
final static int MAX = 30000;
static long[] w = new long[MAX+1];
public static void main(String... args)
{
w[0] = 1;
dp(5);
dp(10);
dp(20);
dp(50);
dp(100);
dp(200);
dp(500);
dp(1000);
dp(2000);
dp(5000);
dp(10000);
while (testcase())
;
}
public static boolean testcase()
{
String str = sc.nextLine();
int price = (int) ((Double.parseDouble(str)) * 100 + 0.5);
if (price == 0)
return false;
System.out.printf("%6s%17s%n", str, "" + w[price]);
return true;
}
static void dp(int c)
{
for (int i = 0; i <= MAX; i++)
{
if (i+c > MAX)
return;
w[i+c] += w[i];
}
}
}