-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy path66.java
More file actions
49 lines (29 loc) · 728 Bytes
/
66.java
File metadata and controls
49 lines (29 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Solution {
public double[] twoSum(int n) {
int dp[][] = new int[n+1][6*n+1];
double result[] = new double[5*n+1];
double x = Math.pow(6,n);
for(int i=1;i<=6;i++)
{
dp[1][i]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=i;j<=6*n;j++)
{
for(int k=1;k<=6;k++)
{
if(j>=k)
{
dp[i][j]+=dp[i-1][j-k];
}
if(i==n)
{
result[j-i]=dp[i][j]/x;
}
}
}
}
return result;
}
}