当前位置:网站首页>POJ 1742 coins (monotone queue solution) [suggestions collection]
POJ 1742 coins (monotone queue solution) [suggestions collection]
2022-07-07 20:16:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Blog .
Plus, if the volume is equal to the value, it's better to do . Only j %v[ i ] The rest of the same ability can be handled at the same time (j It refers to the value of a certain volume ), When calculating a number , Just calculate the same remainder as before ( Within the number limit ) Is there a true( It's full ) You can .
Code :
#include<iostream>
#include<sstream>
#include<map>
#include<cmath>
#include<fstream>
#include<queue>
#include<vector>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<bitset>
#include<ctime>
#include<string>
#include<cctype>
#include<iomanip>
#include<algorithm>
using namespace std ;
#define INT long long int
#define L(x) (x * 2)
#define R(x) (x * 2 + 1)
const int INF = 0x3f3f3f3f ;
const double esp = 0.0000000001 ;
const double PI = acos(-1.0) ;
const int mod = 1000000007 ;
const int MY = (1<<5) + 5 ;
const int MX = 100010 + 5 ;
int n ,W ,ans ;
int v[MX] ,num[MX] ;
bool deq[MX] ,dp[MX] ;
void input()
{
memset(dp ,false ,sizeof(dp)) ;
for(int i = 1 ;i <= n ; ++i)
scanf("%d" ,&v[i]) ;
for(int i = 1 ;i <= n ; ++i)
scanf("%d" ,&num[i]) ;
}
void DP(int v ,int num)
{
if(!num || !v) return ;
if(num == 1) // 01 knapsack
{
for(int i = W ;i >= v ; --i)
if(!dp[i] && dp[i-v])
dp[i] = true ,ans++ ;
}
else if(num * v >= W) // It's all backpacks
{
for(int i = v ;i <= W ; ++i)
if(!dp[i] && dp[i-v])
dp[i] = true ,ans++ ;
}
else
{
num = min(num ,W/v) ;
for(int a = 0 ;a < v ; ++a) // Similarly, the remainder is processed together
{
int front =0 ,end = 0 ,sum = 0 ;
for(int j = a ;j <= W ; j += v)
{
if(end - front-1 == num) // Remove obsolete elements , Due to the most choices num[i] individual
sum -= deq[front++] ;
deq[end++] = dp[j] ; // Deposit in
sum += dp[j] ;
if(!dp[j] && sum)
dp[j] = true ,ans++ ;
}
}
}
}
int main()
{
//freopen("input.txt" ,"r" ,stdin) ;
while(scanf("%d%d" ,&n ,&W) ,n+W)
{
input() ;
dp[0] = true ;
ans = 0 ;
for(int i = 1 ;i <= n ; ++i)
DP(v[i] ,num[i]) ;
printf("%d\n" ,ans) ;
}
return 0 ;
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116515.html Link to the original text :https://javaforall.cn
边栏推荐
- MRS离线数据分析:通过Flink作业处理OBS数据
- 力扣 643. 子数组最大平均数 I
- Force buckle 599 Minimum index sum of two lists
- 【mysql篇-基础篇】事务
- Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
- Force buckle 912 Sort array
- 毕业季|遗憾而又幸运的毕业季
- Ways to improve the utilization of openeuler resources 01: Introduction
- 基于深度学习的目标检测的更新迭代总结(持续更新ing)
- ASP. Net learning & ASP's one word
猜你喜欢

Ways to improve the utilization of openeuler resources 01: Introduction

数据孤岛是企业数字化转型遇到的第一道险关

LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字

Detailed explanation of Flink parallelism and slot

【STL】vector

Opencv learning notes high dynamic range (HDR) imaging

Opencv学习笔记 高动态范围 (HDR) 成像

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

AIRIOT助力城市管廊工程,智慧物联守护城市生命线

Data island is the first danger encountered by enterprises in their digital transformation
随机推荐
CIS芯片测试到底怎么测?
841. 字符串哈希
Force buckle 643 Subarray maximum average I
毕业季|遗憾而又幸运的毕业季
Cloud 组件发展升级
如何在软件研发阶段落地安全实践
力扣674. 最长连续递增序列
mock. JS returns an array from the optional data in the object array
力扣 88.合并两个有序数组
Compiler optimization (4): inductive variables
搞定带WebKitFormBoundary post登录
【STL】vector
Oracle 存儲過程之遍曆
【STL】vector
Force buckle 599 Minimum index sum of two lists
基于深度学习的目标检测的更新迭代总结(持续更新ing)
Force buckle 2315 Statistical asterisk
c语言如何判定是32位系统还是64位系统
CSDN语法说明
浅尝不辄止系列之试试腾讯云的TUIRoom(晚上有约,未完待续...)