File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -1036,6 +1036,9 @@ Trivial circle slicing.
1036
1036
P10080.cpp: Gopher II
1037
1037
Use Modified Ford-Fulkerson for Maximum Bipartite Matching: http://www.geeksforgeeks.org/maximum-bipartite-matching/
1038
1038
1039
+ P10081.java: Tight Words
1040
+ BigDecimal, percentage fraction.
1041
+
1039
1042
P10082.cpp: WERTYU
1040
1043
Char substitution, use string to build substitution array.
1041
1044
You can’t perform that action at this time.
0 commit comments