Skip to content

Commit 247a8cc

Browse files
committed
Added P10081.
1 parent 43191d2 commit 247a8cc

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

P10081.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import java.math.*;
2+
import java.util.Scanner;
3+
4+
public class P10081 {
5+
public static void main(String[] args) throws Exception {
6+
BigInteger HUNDRED = BigInteger.valueOf(100);
7+
String ret[][] = new String[8][101];
8+
9+
BigInteger tight[][] = new BigInteger[10][101]; // 0..k, n
10+
11+
for(int k = 2; k <= 9; ++k) {
12+
BigInteger KPLUSONE = BigInteger.valueOf(k+1);
13+
14+
for(int i = 0; i <= k; ++i)
15+
tight[i][1] = BigInteger.ONE; // One string of length 1 ends with i.
16+
BigInteger ALL = KPLUSONE;
17+
18+
for(int n = 2; n <= 100; ++n) {
19+
BigInteger SUM = BigInteger.ZERO;
20+
for(int i = 0; i <= k; ++i) {
21+
tight[i][n] = tight[i][n-1];
22+
if(i > 0)
23+
tight[i][n] = tight[i][n].add(tight[i-1][n-1]);
24+
if(i < k)
25+
tight[i][n] = tight[i][n].add(tight[i+1][n-1]);
26+
SUM = SUM.add(tight[i][n]);
27+
}
28+
29+
// set ret:
30+
ALL = ALL.multiply(KPLUSONE);
31+
BigDecimal N = new BigDecimal(SUM.multiply(HUNDRED));
32+
BigDecimal D = new BigDecimal(ALL);
33+
ret[k-2][n] = N.divide(D, 5, BigDecimal.ROUND_HALF_UP).toPlainString();
34+
35+
}
36+
}
37+
38+
Scanner s = new Scanner(System.in);
39+
while(s.hasNext()) {
40+
int k = s.nextInt();
41+
int n = s.nextInt();
42+
if(k <= 1 || n <= 1)
43+
System.out.println("100.00000");
44+
else
45+
System.out.println(ret[k-2][n]);
46+
}
47+
48+
}
49+
}

keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,9 @@ Trivial circle slicing.
10361036
P10080.cpp: Gopher II
10371037
Use Modified Ford-Fulkerson for Maximum Bipartite Matching: http://www.geeksforgeeks.org/maximum-bipartite-matching/
10381038

1039+
P10081.java: Tight Words
1040+
BigDecimal, percentage fraction.
1041+
10391042
P10082.cpp: WERTYU
10401043
Char substitution, use string to build substitution array.
10411044

0 commit comments

Comments
 (0)