当前位置:网站首页>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
边栏推荐
- .net(二) 配置数据库
- C语言:调整奇数偶数顺序
- pip3换源提升速度
- 种子数据报错:liquibase.exception.ValidationFailedException: Validation Failed
- 在今天这个特殊的日子,我想要开始我的代码技术博客之路
- Redis(八)集群
- 世界顶尖3D Web端渲染引擎:HOOPS Communicator技术介绍(一)
- (三)、时间序列预测
- Kotlin Coroutines - Exception Handling
- Four departments including the Ministry of Industry and Information Technology promote green smart home products to the countryside
猜你喜欢
随机推荐
204. Count Primes
pc端ncnn搭建与测试
测试流程
Shell之函数与数组
我的创作纪念日
(四)BP神经网络预测(上)
设备指纹详解之识别垃圾账号
BIM技术多牛逼?BIM技术在建筑工程行业的四大发展趋势
SSM integration development case
App测试
配置本地yum源仓库
RAID配置实战
LeetCode: 876. The middle node of the linked list —— simple
浅谈Endpoint
安全的Md5加密:两次加密(加盐)
浅谈Flask_script
BGP路由协议的那些事?(中)
Oracle 限制时将空值排除
nvm安装以及管理多版本node教程
Selenium测试案例一步步学之(2)Selenium自动测试脚本模块化(下)