Skip to content

Commit

Permalink
add 1420
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Apr 23, 2020
1 parent b836fc1 commit dc5b00a
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,5 @@ LeetCode
|1416|[Restore The Array](https://leetcode.com/problems/restore-the-array/)|c|[c++](./src/1416-Restore-The-Array/1416.cpp)|[python](./src/1416-Restore-The-Array/1416.py)|[go](./src/1416-Restore-The-Array/1416.go)|[js](./src/1416-Restore-The-Array/1416.js)|[java](./src/1416-Restore-The-Array/1416.java)|Hard|
|1417|[Reformat The String](https://leetcode.com/problems/reformat-the-string/)|c|[c++](./src/1417-Reformat-The-String/1417.cpp)|[python](./src/1417-Reformat-The-String/1417.py)|[go](./src/1417-Reformat-The-String/1417.go)|[js](./src/1417-Reformat-The-String/1417.js)|[java](./src/1417-Reformat-The-String/1417.java)|Easy|
|1418|[Display Table of Food Orders in a Restaurant](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant/)|c|[c++](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.cpp)|[python](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.py)|[go](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.go)|[js](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.js)|[java](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.java)|Medium|
|1419|[Minimum Number of Frogs Croaking](https://leetcode.com/problems/minimum-number-of-frogs-croaking/)|c|[c++](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp)|[python](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.py)|[go](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.go)|[js](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.js)|[java](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.java)|Medium|
|1419|[Minimum Number of Frogs Croaking](https://leetcode.com/problems/minimum-number-of-frogs-croaking/)|c|[c++](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp)|[python](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.py)|[go](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.go)|[js](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.js)|[java](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.java)|Medium|
|1420|[Build Array Where You Can Find The Maximum Exactly K Comparisons](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons/)|c|[c++](./src/1420-Build-Array-Where-You-Can-Find-The-Maximum-Exactly-K-Comparisons/1420.cpp)|[python](./src/1420-Build-Array-Where-You-Can-Find-The-Maximum-Exactly-K-Comparisons/1420.py)|[go](./src/1420-Build-Array-Where-You-Can-Find-The-Maximum-Exactly-K-Comparisons/1420.go)|[js](./src/1420-Build-Array-Where-You-Can-Find-The-Maximum-Exactly-K-Comparisons/1420.js)|[java](./src/1420-Build-Array-Where-You-Can-Find-The-Maximum-Exactly-K-Comparisons/1420.java)|Hard|
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int numOfArrays(int n, int m, int k) {
int mod = 1000000007;
long long dp[n + 1][k + 1][m + 1];
memset(dp, 0, sizeof dp);

for (int c = 0; c <= m; c++) dp[1][1][c] = c;
for (int a = 2; a <= n; a++) {
for (int b = 1; b <= k; b++) {
for (int c = b; c <= m; c++) {
dp[a][b][c] = (dp[a][b][c - 1] + dp[a - 1][b - 1][c - 1] +
(dp[a - 1][b][c] - dp[a - 1][b][c - 1] + mod) * c) % mod;
}
}
}
return dp[n][k][m];
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
func numOfArrays(n int, m int, k int) int {
mod := 1000000007
dp := make([][][]int, n + 1)
for i := 0; i <= n; i++ {
dp[i] = make([][]int, k + 1)
for j := 0; j <= k; j++ {
dp[i][j] = make([]int, m + 1)
}
}

for c := 0; c <= m; c++ {
dp[1][1][c] = c
}
for a := 2; a <= n; a++ {
for b := 1; b <= k; b++ {
for c := b; c <= m; c++ {
dp[a][b][c] = (dp[a][b][c - 1] + dp[a - 1][b - 1][c - 1] +
(dp[a - 1][b][c] - dp[a - 1][b][c - 1] + mod) * c) % mod
}
}
}
return dp[n][k][m]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public int numOfArrays(int n, int m, int k) {
long mod = 1000000007;
long[][][] dp = new long[n + 1][k + 1][m + 1];

for (int c = 0; c <= m; c++) dp[1][1][c] = c;
for (int a = 2; a <= n; a++) {
for (int b = 1; b <= k; b++) {
for (int c = b; c <= m; c++) {
dp[a][b][c] = (dp[a][b][c - 1] + dp[a - 1][b - 1][c - 1] +
(dp[a - 1][b][c] - dp[a - 1][b][c - 1] + mod) * c) % mod;
}
}
}
return (int)(dp[n][k][m]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var numOfArrays = function(n, m, k) {
let mod = 1000000007;
let dp = Array(n + 1);
for (let i = 0; i <= n; i++) {
dp[i] = Array(k + 1);
for (let j = 0; j <= k; j++) {
dp[i][j] = Array(m + 1).fill(0);
}
}

for (let c = 0; c <= m; c++) dp[1][1][c] = c;
for (let a = 2; a <= n; a++) {
for (let b = 1; b <= k; b++) {
for (let c = b; c <= m; c++) {
dp[a][b][c] = (dp[a][b][c - 1] + dp[a - 1][b - 1][c - 1] +
(dp[a - 1][b][c] - dp[a - 1][b][c - 1] + mod) * c) % mod;
}
}
}
return dp[n][k][m];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def numOfArrays(self, n: int, m: int, k: int) -> int:
mod = 10**9 + 7

dp = [[[0] * (m + 1) for _ in range(k + 1)] for _ in range(n + 1)]
for c in range(m + 1):
dp[1][1][c] = c
for a in range(2, n + 1):
for b in range(1, k + 1):
for c in range(b, m + 1):
dp[a][b][c] = (dp[a][b][c - 1] + dp[a - 1][b - 1][c - 1] + \
(dp[a - 1][b][c] - dp[a - 1][b][c - 1] + mod) * c) % mod
return dp[-1][-1][-1]
8 changes: 4 additions & 4 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os, bisect

# 题目名称
name = "Minimum Number of Frogs Croaking"
ID = 1419
url = "https://leetcode.com/problems/minimum-number-of-frogs-croaking/"
difficult = "Medium"
name = "Build Array Where You Can Find The Maximum Exactly K Comparisons"
ID = 1420
url = "https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons/"
difficult = "Hard"
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']


Expand Down

0 comments on commit dc5b00a

Please sign in to comment.