包子凑数

类似完全背包求方案数,再加上点数论知识,裴蜀定理。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=300000;
bool  f[N];
int a[120];
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,n0=0,n1=0; cin>>n;
	f[0]=1;
	int g;
	for(int i=1;i<=n;i++) cin>>a[i];
	g=a[1];
	for(int i=1;i<=n;i++)
	{
		g=__gcd(g,a[i]);
		for(int j=a[i];j<N;j++)
		f[j]|=f[j-a[i]];
	}
	int flag=0,cnt=0;
	for(int i=1;i<N;i++)
	if(!f[i]) 
	cnt++;
	if(g!=1){
		cout<<"INF";
		return 0;
	}
     cout<<cnt;
	return 0;
}
相关推荐
Wendy_robot1 小时前
【滑动窗口+哈希表/数组记录】Leetcode 438. 找到字符串中所有字母异位词
c++·算法·leetcode
转基因1 小时前
Codeforces Round 1020 (Div. 3)(题解ABCDEF)
数据结构·c++·算法
whoarethenext2 小时前
c++的jsoncpp使用
开发语言·c++·jsoncpp
我想进大厂3 小时前
图论---Kruskal(稀疏图)
数据结构·c++·算法·图论
_w_z_j_3 小时前
C++----模拟实现string
开发语言·c++
特立独行的猫a3 小时前
redis客户端库redis++在嵌入式Linux下的交叉编译及使用
linux·数据库·c++·redis·redis客户端库
张槊哲3 小时前
const(C++)
开发语言·c++
oioihoii3 小时前
C++23 中 constexpr 的重要改动
c++·算法·c++23
pystraf4 小时前
UOJ 228 基础数据结构练习题 Solution
数据结构·c++·算法·线段树
牙痛不能吃糖,哭4 小时前
C++面试复习日记(8)2025.4.25,malloc,free和new,delete的区别
开发语言·c++