当前位置:网站首页>Buns make up the number----Euclide+dp
Buns make up the number----Euclide+dp
2022-08-09 08:02:00 【scwMason】
Title description:
Xiao Ming eats breakfast at a steamed bun shop almost every morning.He found that this steamed bun shop has N kinds of steamers, and the i-th steamer can hold Ai buns exactly.Each type of steamer has a very large number of cages, which can be considered as infinite cages.Whenever a customer wants to buy X steamed buns, the uncle who sells steamed buns will quickly select a number of steamed buns, so that there are exactly X steamed buns in these cages.For example, there are 3 types of steamers, which can hold 3, 4 and 5 buns respectively.When a customer wants to buy 11 buns, the uncle will choose 2 cages of 3 plus 1 cage of 5 (may also choose 1 cage of 3 plus 2 cages of 4).Of course, sometimes Uncle Baozi can't make up the quantity that customers want to buy anyway.For example, there are 3 types of steamers, which can hold 4, 5 and 6 buns respectively.And when the customer wanted to buy 7 buns, the uncle couldn't come out.
Xiao Ming wants to know how many kinds of numbers there are that Uncle Baozi can't come up with.
Input
----
The first line contains an integer N.(1 <= N <= 100)
Each of the following N lines contains an integer Ai.(1 <= Ai <= 100)
Output
----
An integer representing the answer.If there are infinite numbers that cannot be made up, output INF.
For example,
Input:
2
4
5
The program should output:
6
Another example,
Input:
2
> 4
6
The program should output:
INF
Example explanation:
For example 1, the numbers that cannot be made up include: 1, 2, 3, 6, 7, 11.
For example 2, all odd numbers cannot be made up, so there are infinitely many.
Resource convention:
Peak memory consumption (including virtual machine) < 256M
CPU consumption < 1000ms
Please output strictly as required, do not superfluous print something like: "Please enter..."redundant content.
Note:
The main function needs to return 0;
Only use the ANSI C/ANSI C++ standard;
Do not call special functions that depend on the compilation environment or operating system.
All dependent functions must be explicitly #include
Common header files cannot be omitted through project settings.
When submitting your program, take care to select the desired language type and compiler type.
Thinking:
1. Under what circumstances will INF be output?
For example, the above case: 2 4 6, as long as it is an odd number, he can't make it up, because the least common divisor of these three numbers is 2, and only the least common divisor is 1 can it be made up
2. How to determine which ones cannot be assembled?
You can set a dp array, loop:
dp[0] = 1;for (int i = 0; i < n; i++){for (int j = 0; j + arr[i] < 100001; j++){if (dp[j])dp[j + arr[i]] = 1;}}
If you can figure it out, dp[i]=1
Code:
#include using namespace std;bool judge(int x, int y){int t;while(y>0){t=x%y;x=y;y=t;}if(x==1)return true;return false;}int a[110],n;bool dp[10010];int main(){scanf("%d",&n);for(int i=0; i
边栏推荐
猜你喜欢
[STL]list
LeetCode·每日一题·636.函数的独占时间·栈模拟
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
Redis(八)集群
CoCube传感器MPU6050笔记
【无标题】
Data storage implementation of SDRAM and read and write operations on its data
静态路由的原理与配置
SA-Siam:用于实时目标跟踪的双重连体网络A Twofold Siamese Network for Real-Time Object Tracking
Exclude null values when Oracle limits
随机推荐
.net(四) 数据层实现
接口测试概念
Cookie和Session详解
Apache POI
传输层协议介绍
2019 Nanchang Internet Competition Question C, Hello 2019
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
贪吃蛇小游戏——C语言
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
Kotlin协程 - 异常处理
[STL]vector
VOC format label to YOLO format
CUDA和cuDNN 安装10.0版本
Collection 接口 & List 接口
libtorch示例
The String class objects created by the JVM memory allocation and the difference between equals and = =
测试流程
oracle存储过程问题解答
C语言:字符逆序
C语言:调整奇数偶数顺序