当前位置:网站首页>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 边栏推荐
猜你喜欢
随机推荐
传输层协议介绍
resourcemanager启动失败,别的节点成功
Anaconda replaces the default virtual environment
Set集合
VMware虚拟机强制关闭后,无法联网
C: print the diamond
BGP路由协议的那些事?(中)
Shell之函数与数组
Non-decreasing Array
如何把无用的代码注释为 Deprecated 弃用
SDRAM的数据存储实现并对其数据进行读写操作
Web 3D渲染引擎HOOPS Communicator动画编辑器的使用 | HOOPS教程
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
App测试
Unity 3D模型展示框架篇之资源打包、加载、热更(二)
Jmeter连接Mysql和Mysql编码问题
HOOPS是什么?这4款3D软件开发工具包你还不知道?
静态路由的原理与配置
.net(一)WebService创建
Redis(八)集群






![[STL]stack与queue](/img/a8/b3093cb4bf03ced1614c790decc336.png)

