-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
32 lines (32 loc) · 727 Bytes
/
Solution.cs
File metadata and controls
32 lines (32 loc) · 727 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
public class Solution
{
public int IntegerBreak(int n)
{
// n = 58
int[][] dp = new int[n + 1][];
for (int i = 0; i <= n; i++)
{
dp[i] = new int[n + 1];
}
for (int i = 0; i <= n; i++)
{
dp[i][0] = i;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
for (int k = 0; k < i; k++)
{
dp[i][j] = Math.Max(dp[i][j], dp[k][j - 1] * (i - k));
}
}
}
int ret = 0;
for (int i = 1; i <= n; i++)
{
ret = Math.Max(ret, dp[n][i]);
}
return ret;
}
}