当前位置:网站首页>Number of solutions for knapsack problem
Number of solutions for knapsack problem
2022-06-26 17:26:00 【Zqchang】
Catalog
thought
Same as the shortest circuit , because dp The topology is the shortest path 
In the shortest circuit , If there are two points with the same distance to the end , Then the sum of the two schemes is the answer
Recall the state transition equation 
The state here is , No more than j The greatest value of time
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1010, mod = 1e9 + 7;
int n, m;
int f[N], g[N];
int main()
{
cin >> n >> m;
f[0] = 0;
g[0] = 1;
for (int i = 0; i < n; i ++ )
{
int v, w;
cin >> v >> w;
for (int j = m; j >= v; j -- )
{
int maxv = max(f[j], f[j - v] + w);
int s = 0;
if (f[j] == maxv) s = g[j];
if (f[j - v] + w == maxv) s = (s + g[j - v]) % mod;
f[j] = maxv, g[j] = s;
}
}
int sum = 0;
for (int i = 0; i <= m; i ++ )
if (f[i] == f[m])
sum = (sum + g[i]) % mod;
cout << sum << endl;
return 0;
}
边栏推荐
- Quantitative contract system development analysis case - detailed explanation of contract quantitative system development scheme
- Some explanations for latex CJK
- 【万字总结】以终为始,详细分析高考志愿该怎么填
- Deployment and operation of mongodb partitioned cluster
- 牛客网:设计LRU缓存结构 设计LFU缓存结构
- MySQL index
- Don't believe it, 98% of programmers are like this
- [latex bearer] use tables in \title (error \begin doesn't match its definition.)
- What does the equals method compare? Who told you
- Vue--vuerouter cache routing component
猜你喜欢

Treasure and niche CTA animation material website sharing

Platform management background and merchant menu resource management: Design of platform management background data service

What is the difference between digital collections and NFT

数字藏品与NFT到底有何区别
![[recommendation system learning] technology stack of recommendation system](/img/ff/afc6f4b0997cfcb9e01ffbebf2a872.png)
[recommendation system learning] technology stack of recommendation system

丰富专业化产品线, 江铃福特领睿·极境版上市

Troubleshooting ideas that can solve 80% of faults!

类型多样的石膏PBR多通道贴图素材,速来收藏!

Strength and appearance Coexist -- an exclusive interview with Liu Yu, a member of Apache pulsar PMC

Uncover the secret of Agora lipsync Technology: driving portraits to simulate human speech through real-time voice
随机推荐
国信证券怎么开户?通过链接办理股票开户安全吗
丰富专业化产品线, 江铃福特领睿·极境版上市
Leetcode topic [array] -268- missing numbers
牛客网:设计LRU缓存结构 设计LFU缓存结构
SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
Distributed Architecture Overview
类型多样的石膏PBR多通道贴图素材,速来收藏!
Alibaba's "high concurrency" tutorial "basic + actual combat + source code + interview + Architecture" is a god class
[ten thousand words summary] starting from the end, analyze in detail how to fill in the college entrance examination volunteers
[suggested collection] 11 online communities suitable for programmers
Don't believe it, 98% of programmers are like this
sql中ROUND和TRUNCATE的区别(四舍五入还是截取小数点后几位)
Wechat app mall, review products, upload commodity pictures, and score Commodity Services
14《MySQL 教程》INSERT 插入数据
COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
Demonstrate to Xiaobai the case of sub database and sub table
20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)
The texstudio official website cannot be opened
离婚协议中的几个重点
Use FST JSON to automatically generate faster JSON serialization methods