当前位置:网站首页>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
边栏推荐
- Entity alignment two of knowledge map
- Swagger UI教程 API 文档神器
- 拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条
- 039. (2.8) thoughts in the ward
- New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
- How to implement common frameworks
- 【OpenCV 例程200篇】220.对图像进行马赛克处理
- HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
- C language games - minesweeping
- Pycharm remote execution
猜你喜欢
【微信小程序】運行機制和更新機制
Swagger UI教程 API 文档神器
Opencv learning example code 3.2.3 image binarization
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
Manifest of SAP ui5 framework json
PHP online examination system version 4.0 source code computer + mobile terminal
[MySQL] basic use of cursor
use. Net analysis Net talent challenge participation
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条
968 edit distance
随机推荐
Huawei device command
'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
【微信小程序】运行机制和更新机制
[asp.net core] set the format of Web API response data -- formatfilter feature
C language games - three chess
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
强化学习-学习笔记5 | AlphaGo
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
document.write()的用法-写入文本——修改样式、位置控制
Xcode6 error: "no matching provisioning profiles found for application"
js中,字符串和数组互转(一)——字符串转为数组的方法
039. (2.8) thoughts in the ward
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
Spiral square PTA
966 minimum path sum
ICML 2022 | flowformer: task generic linear complexity transformer
PG basics -- Logical Structure Management (transaction)
Redis insert data garbled solution
Swagger UI教程 API 文档神器