当前位置:网站首页>ACdreamoj1110(多重背包)
ACdreamoj1110(多重背包)
2022-07-06 12:55:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
意甲冠军:多个裸露的双肩背包。水的问题。
解决方法:然背包一样,仅仅只是加一个数组,记录着每一个物品用过的次数,多于存储量时就pass不更新。
另一种方法是将每一个物品用二进制压缩处理。第一个代码比較简单;
代码:
/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std;
#define eps 1e-8
#define zero(_) (abs(_)<=eps)
const double pi=acos(-1.0);
typedef long long LL;
const int Max=100010;
const int INF=1000000007;
int a[103];
int num[103];
int rem[Max];
bool ans[Max];
int n,cap;
int main()
{
int t;
//cout<<pow(6,4)-1<<endl;
scanf("%d",&t);int kk=1;
while(t--)
{
memset(ans,0,sizeof ans);
scanf("%d%d",&n,&cap);
for(int i=0; i<n; i++)
scanf("%d",a+i);
for(int i=0; i<n; i++)
scanf("%d",num+i);
ans[0]=1;
for(int i=0; i<n; i++)
{
memset(rem,0,sizeof rem);
for(int j=0; j<=cap; j++)
{
if(j+a[i]>cap||rem[j]>=num[i])
continue;
if(ans[j])
{
if(ans[j+a[i]])
{
rem[j+a[i]]=min(rem[j+a[i]],rem[j]+1);
continue;
}
ans[j+a[i]]=1;
rem[j+a[i]]=rem[j]+1;
}
}
}
int out=0;
for(int i=1; i<=cap; i++)
if(ans[i])
out++;
printf("Case %d: %d\n",kk++,out);
}
return 0;
}
/*
4 100000
1 12 456 5678
5 5 5 5
*/版权声明:本文博主原创文章,博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117094.html原文链接:https://javaforall.cn
边栏推荐
- 基于STM32单片机设计的红外测温仪(带人脸检测)
- Yyds dry goods count re comb this of arrow function
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- What is the problem with the SQL group by statement
- Regular expression collection
- 数据湖(八):Iceberg数据存储格式
- 面试官:Redis中有序集合的内部实现方式是什么?
- HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
- 快过年了,心也懒了
- Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
猜你喜欢

What key progress has been made in deep learning in 2021?

After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers

Is this the feeling of being spoiled by bytes?

【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug

The biggest pain point of traffic management - the resource utilization rate cannot go up

Study notes of grain Mall - phase I: Project Introduction

1_ Introduction to go language

for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环

3D face reconstruction: from basic knowledge to recognition / reconstruction methods!

No Yum source to install SPuG monitoring
随机推荐
The biggest pain point of traffic management - the resource utilization rate cannot go up
Reflection operation exercise
Swagger UI教程 API 文档神器
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Deployment of external server area and dual machine hot standby of firewall Foundation
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Xcode6 error: "no matching provisioning profiles found for application"
use. Net drives the OLED display of Jetson nano
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
Mtcnn face detection
Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
Dynamically switch data sources
每个程序员必须掌握的常用英语词汇(建议收藏)
Simple continuous viewing PTA
面试官:Redis中有序集合的内部实现方式是什么?
js通过数组内容来获取数组下标
【mysql】游标的基本使用
js中,字符串和数组互转(二)——数组转为字符串的方法
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
Word bag model and TF-IDF