当前位置:网站首页>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
边栏推荐
- c#使用oracle存储过程获取结果集实例
- 7. Data permission annotation
- C language games - three chess
- 快过年了,心也懒了
- js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
- MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
- use. Net drives the OLED display of Jetson nano
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- PHP online examination system version 4.0 source code computer + mobile terminal
- @PathVariable
猜你喜欢
The biggest pain point of traffic management - the resource utilization rate cannot go up
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
性能测试过程和计划
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
15 millions d'employés sont faciles à gérer et la base de données native du cloud gaussdb rend le Bureau des RH plus efficace
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
数据湖(八):Iceberg数据存储格式
Detailed explanation of knowledge map construction process steps
随机推荐
Swagger UI教程 API 文档神器
1_ Introduction to go language
Data Lake (VIII): Iceberg data storage format
Simple continuous viewing PTA
性能测试过程和计划
ICML 2022 | flowformer: task generic linear complexity transformer
Huawei device command
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
No Yum source to install SPuG monitoring
What is the problem with the SQL group by statement
js中,字符串和数组互转(二)——数组转为字符串的方法
Xcode6 error: "no matching provisioning profiles found for application"