当前位置:网站首页>Blue Bridge Cup: Candy
Blue Bridge Cup: Candy
2022-06-21 07:58:00 【lsgoose】
Title Description
The owners of the candy store have MM Kinds of sweets for sale . For ease of description , We will MM A flavor number 1∼ MM.
Xiaoming hopes to taste all kinds of sweets . Unfortunately, the boss doesn't sell candy alone , It is KK One bag for sale .
It's a good thing that the candy package says KK The taste of a candy , So Xiaoming can know the taste of candy in each package before buying it .
Given NN Pack candy , Please calculate how many bags Xiaoming should buy at least , You can taste all kinds of candy .
Output description
Output an integer for the answer . If Xiaoming can't taste all the flavors , Output −1.
I/o sample
Example
Input
6 5 3
1 1 2
1 2 3
1 1 3
2 3 5
5 4 2
5 1 2
Output
2
Operation limit
- Maximum operation time :1s
- Maximum running memory : 256M
It's clever , For the first time, I have encountered this kind of binary dynamic programming , Here, an array is used to store the status of each package ,
The code is as follows :
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f,N=1e2+7;
int bag[N];
int f[1<<20];
int main()
{
// Please enter your code here
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
int all=(1<<m)-1;
for(int i=0;i<=all;++i) f[i]=INF;
for(int i=0;i<n;++i)
{
int tmp=0,state=0;
for(int j=0;j<k;++j)
{
scanf("%d",&tmp);
tmp--;
state |= 1<<tmp;
}
bag[i]=state;
f[state]=1;
}
for(int i=0;i<n;++i)
{
for(int j=0;j<=all;++j)
{
if(f[j]==INF) continue;
f[j|bag[i]]=min(f[j|bag[i]],f[j]+1);
}
}
if(f[all]==INF) cout<<-1<<endl;
else cout<<f[all]<<endl;
return 0;
}边栏推荐
- Parameter estimation -- a general problem of parameter estimation
- Upgrade Jenkins steps and problems encountered
- 虚拟机浏览器花屏空白问题
- Learning Tai Chi maker esp8226 (IX) JSON data communication III
- How to write the statement of executing stored procedure in MySQL
- 2022年的WordPress网站安全问题
- Operator priority and combining order
- How MySQL closes a transaction
- [putty] a free SSH and telnet client
- (对于换行符)gets和fgets的区别,puts和fputs的区别
猜你喜欢

解决Jenkins升级后不能保存配置的问题

Matlab 3D diagram (unconventional)

群暉DSM7添加套件源

Dynamic programming to solve the problem of looting

Learning Tai Chi maker esp8226 (IX) JSON data communication III

Wanzi detailed data warehouse, data lake, data middle platform and lake warehouse are integrated
![[kotlin] premier jour](/img/51/18b394a6bf0ab74b71e5c59ad3341c.png)
[kotlin] premier jour

2022年的WordPress网站安全问题

Illustration Google V8 14: bytecode (2): how does the interpreter interpret and execute bytecode?

Software download method
随机推荐
Eureka的TimedSupervisorTask类(自动调节间隔的周期性任务)
144. preorder traversal of binary tree
群晖DSM7添加套件源
17 statistics and their sampling distribution statistics and distribution
One year experience interview byte Tiktok e-commerce, share the following experience!
学习太极创客 — ESP8226 (九)JSON 数据通讯 三
2021-06-16 STM32F103 EXTI 中断识别 使用固件库
Yunkang group passed the hearing: the revenue exceeded 1billion in 8 months and the profit within the period was 270Million
Matlab 3D diagram (unconventional)
Horizontal slot, one line of code can directly convert the web page to PDF and save it (pdfkit)
Software download method
【kotlin】第一天
Ansa secondary development - external programs use socket to communicate with ansa
2021-07-28 STM32F103 I2C Hardware Transfer Include previous IO Clock EXIT USB use firmware library
Permission management
2021 - 06 - 16 stm32f103 exti interruption identification using firmware Library
Operator priority and combining order
PostgreSQL数据库头胎——后台一等公民进程StartupDataBase StartupXLOG函数进入Recovery模式
/home/ljx/miniconda3/compiler_compat/ld: cannot find crtbeginS.o: 没有那个文件或目录
Qunhui dsm7 add kit source
