Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f9b724a

Browse files
committedMar 27, 2022
Time: 329 ms (11.68%), Space: 10.4 MB (18.18%) - LeetHub
1 parent 675764f commit f9b724a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class Solution {
2+
public:
3+
4+
int dp[101][101][101];
5+
int mod=1e9+7;
6+
int dfs(int i,int n, int m, int k,int mx,int cost)
7+
{
8+
if(i==n)
9+
{
10+
if(cost==k)
11+
{
12+
return 1;
13+
}
14+
return 0;
15+
}
16+
if(dp[i][mx][cost]!=-1)
17+
{
18+
return dp[i][mx][cost];
19+
}
20+
int ans=0;
21+
for(int j=1;j<=m;j++)
22+
{
23+
int a=0;
24+
if(j>mx)
25+
{
26+
a=dfs(i+1,n,m,k,j,cost+1)%mod;
27+
}
28+
else
29+
{
30+
// a=dfs(n,m,k,max(mx,j),cost+j>mx?1:0,i+1)%mod;
31+
a=dfs(i+1,n,m,k,mx,cost)%mod;
32+
}
33+
34+
35+
a=a%mod;
36+
ans=ans%mod;
37+
ans=(ans+a)%mod;
38+
}
39+
return dp[i][mx][cost]=ans;
40+
}
41+
42+
43+
int numOfArrays(int n, int m, int k) {
44+
45+
memset(dp,-1,sizeof(dp));
46+
return dfs(0,n,m,k,0,0);
47+
}
48+
};

0 commit comments

Comments
 (0)
Please sign in to comment.