当前位置:网站首页>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;
}
边栏推荐
- 合约量化系统开发方案详细,量化合约系统开发技术说明
- Prometeus 2.34.0 new features
- She said she was tired! So tired! I want to change my career
- 防火 疏散 自救…这场安全生产暨消防培训干货满满!
- How about opening an account at Guojin securities? Is it safe?
- Teach you to learn dapr - 6 Publish subscription
- Interpretation of new plug-ins | how to enhance authentication capability with forward auth
- Find all primes less than or equal to Lim, store them in AA array, and return the number of primes
- Platform management background and merchant menu resource management: Design of platform management background data service
- SQL injection for Web Security (3)
猜你喜欢

Wechat app mall, review products, upload commodity pictures, and score Commodity Services

Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation

Which low code platform is more friendly to Xiaobai? Here comes the professional evaluation!

Niuke network: Design LRU cache structure design LFU cache structure

去中心化NFT交易协议将击败OpenSea

SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用

Demonstrate to Xiaobai the case of sub database and sub table
![[buuctf.reverse] 126-130](/img/df/e35633d85caeff1dece62a66cb7804.png)
[buuctf.reverse] 126-130

7 views on NFT market prospect

Platform management background and merchant menu resource management: Design of platform management background data service
随机推荐
Leetcode daily [2022 - 02 - 16]
Cloud native 02: Alibaba cloud cloud efficient flow pipeline
mysql Add column 失败 因为之前有数据,不是默认null 不行
一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
Teach you to learn dapr - 1 The era of net developers
The high concurrency system is easy to play, and Alibaba's new 100 million level concurrent design quick notes are really fragrant
COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
Detailed explanation of browser storage methods: the origin and difference of cookies, localstorage and sessionstorage
[dynamic planning] Jianzhi offer II 091 Paint the house
Demonstrate to Xiaobai the case of sub database and sub table
MySql 导出数据库中的全部表索引
Various types of gypsum PBR multi-channel mapping materials, please collect them quickly!
并发之线程安全
Fire evacuation and self rescue... This safety production and fire training is full!
Redis OM . Net redis object mapping framework
Teach you to learn dapr - 3 Run the first with dapr Net program
【代码随想录-动态规划】T583、两个字符串的删除操作
丰富专业化产品线, 江铃福特领睿·极境版上市
[latex bearer] use tables in \title (error \begin doesn't match its definition.)
In those years, interview the abused red and black trees