当前位置:网站首页>LeetCode 1155. N ways to roll dice**
LeetCode 1155. N ways to roll dice**
2022-06-09 02:37:00 【Evening rain forest bell】
Specific ideas :
Complete knapsack problem , Stuck in a mess ;
After seeing Sanye, I knew that it was traditional 01 The writing is not bad ;
In fact, the transmission of the past should be a ladder , But from 0 It doesn't hurt to start traversing ;
Specific code :
class Solution {
public:
int numRollsToTarget(int n, int k, int target) {
int mod=1e9+7;
vector<vector<int>>dp(n+1,vector<int>(target+1,0));
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=target;j++){
for(int u=1;u<=k;u++){
if(j>=u){
dp[i][j]=(dp[i][j])%mod+(dp[i-1][j-u])%mod;
dp[i][j]%=mod;
}
}
}
}
return dp[n][target];
}
};
class Solution {
public:
int numRollsToTarget(int n, int k, int target) {
if(target>k*n)
return 0;
int mod=1e9 + 7;
vector<vector<int>>dp(n+1,vector<int>(target+1,0));
dp[0][0]=1;
for(int i=0;i<=min(k,target);i++){
dp[1][i]=1;
}
for(int i=2;i<=n;i++){
for(int j=i;j<=target;j++){
for(int u=1;u<=k;u++){
if(j-u>0){
dp[i][j]=(dp[i][j])%mod+(dp[i-1][j-u])%mod;
dp[i][j]%=mod;
}
}
}
}
return dp[n][target];
}
};
边栏推荐
- 杰理之如何修改 ad_key 连接的引脚?【篇】
- 【编码推流】SRS流媒体服务器安装及使用
- 动态规划/斐波那契数列
- Jedis工具类、适配单个redis以及redis集群
- Common commands for detecting Huawei network devices
- How to modify ad_ Key connected pin? [chapter]
- Docker安装Redis
- From the ECS SSRF vulnerability to taking over your alicloud console
- Go技術日報(2022-06-07)——go程序員開發效率神器匯總
- Basic usage of flask sqlalmy
猜你喜欢

数字电路加法器 基本原理(一)

Modbus RTU communication routine between Delta Eh3 series PLC and thermostat

S series · several postures for deleting folders

Sorting out the soft and hard decoding methods of ffmpeg

Deux facteurs importants affectant la défaillance de togglerowselection ()

Indonesia widya robotics and Huawei cloud make the safety of construction sites visible

Two important influencing factors of togglerowselection() failure

4426 divisible substring (enumeration + number theory)
![[MySQL from Xiaobai to expert] Part 6: transaction and JDBC programming in MySQL](/img/e1/0807247eaf70d0fc95c3399352f1c8.png)
[MySQL from Xiaobai to expert] Part 6: transaction and JDBC programming in MySQL

接口测试系列——转转交易业务场景接口测试实践
随机推荐
The high-end is weak. Can Yanghe still keep the third place in the industry?
Unity中,继承MonoBehaviour游戏对象的生命周期
价值600的抖音云蹦迪直播间项目,靠直播打赏收益的风口项目源码
蓝桥杯_丢番图方程
杰理之SPI 从机如何配置驱动程序?【篇】
Jerry last IO_ Key how to use double keys? [chapter]
Jericho's several descriptions on SPI host configuration parameters]
New textbook for self taught examination-p292
TypeScript 基础类型 —— 类型断言
Implementation of UESTC daily report based on Selenium
Qt: get sender in slot (the control that triggers signal)
杰理之若用户不需要使用所有的按键,其他按键应该如何设置?【篇】
Force deduction solution summary 1037- effective boomerang
Blue Bridge Cup_ Multiple problem_ stack_ Remainder
Greedy method / Huffman code
【无标题】
How does Jerry's SPI host configure the driver? [chapter]
Doris daily function summary I
FFmpeg的软、硬解码方式梳理
Go技术日报(2022-06-07)——go程序员开发效率神器汇总