A.java

/* |\ _,,,---,,_ /,`.-'`' -. ;-;;,_ |,4- ) )-,_..;\ ( `'-' '---''(_/--' `-'\_) Meow do you do ヽ(●´∀`●)οΎ‰ */ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { static BigDecimal take(int n, int r) { BigInteger a = BigInteger.ONE; for (int i = 0; i < r; i++) { a = a.multiply(BigInteger.valueOf(n - i)); a = a.divide(BigInteger.valueOf(1+i)); } BigDecimal b = new BigDecimal(a); b = b.divide(BigDecimal.valueOf(Math.pow(3, n-1)), 50, BigDecimal.ROUND_HALF_DOWN); return b; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); BigDecimal[] f = new BigDecimal[101]; f[1] = BigDecimal.ZERO; for (int i = 2; i <= n; i++) { BigDecimal p = BigDecimal.ZERO; BigDecimal s = BigDecimal.ZERO; for (int j = 1; j < i; j++) { BigDecimal t = take(i, j); p = p.add(t); s = s.add(t.multiply(f[j].add(BigDecimal.ONE))); } s = s.subtract(p.subtract(BigDecimal.ONE)); f[i] = s.divide(p, 10, BigDecimal.ROUND_HALF_DOWN); } System.out.println(f[n].toString()); } }
Solution for NTU 2015.3.14

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.