当前位置: 首页 > news >正文

宁德蕉城住房和城乡建设部网站湖南平台网站建设设计

宁德蕉城住房和城乡建设部网站,湖南平台网站建设设计,网站建设 seo,南京seo关键词优化服务题意 小明几乎每天早晨都会在一家包子铺吃早餐。他发现这家包子铺有N种蒸笼,其中第i种蒸笼恰好能放Ai个包子。每种蒸笼都有非常多笼,可以认为是无限笼。 每当有顾客想买X个包子,卖包子的大叔就会迅速选出若干笼包子来,使得这若干…

题意

小明几乎每天早晨都会在一家包子铺吃早餐。他发现这家包子铺有N种蒸笼,其中第i种蒸笼恰好能放Ai个包子。每种蒸笼都有非常多笼,可以认为是无限笼。

每当有顾客想买X个包子,卖包子的大叔就会迅速选出若干笼包子来,使得这若干笼中恰好一共有X个包子。比如一共有3种蒸笼,分别能放3、4和5个包子。当顾客想买11个包子时,大叔就会选2笼3个的再加1笼5个的(也可能选出1笼3个的再加2笼4个的)。

当然有时包子大叔无论如何也凑不出顾客想买的数量。比如一共有3种蒸笼,分别能放4、5和6个包子。而顾客想买7个包子时,大叔就凑不出来了。

小明想知道一共有多少种数目是包子大叔凑不出来的。

输入与数据范围

第一行包含一个整数NNN(1<=N<=100)(1 <= N <= 100)(1<=N<=100)
以下NNN行每行包含一个整数AiAiAi(1<=Ai<=100)(1 <= Ai <= 100)(1<=Ai<=100)

算法(裴蜀定理,背包问题)

先给出两个数xxxyyy是否能凑出最大数的问题。

  • 如果xxxyyy的最大公约数是1,那么它们存在不能够凑出的最大数,并且它们不能凑出的最大数是:(x−1)×(y−1)−1(x - 1) \times (y - 1) - 1(x1)×(y1)1
  • 在本题中,不能够凑出最大数意味着:他们不能凑出的数是有限的,因为不能够凑出的最大数为upupup,等价着大于upupup的所有数都能够被凑出,那么不能够凑出的数只可能在区间[1,up][1, up][1,up]中,显然,这个区间中的数是有限的。

所以我们先把所有蒸笼所装的包子数的最大公约数ddd给算出来。

// 最大公约数代码
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;
}

如果ddd不等于1,那么他们不存在不能够凑出的最大数,等价于不能够凑出的包子数量为无限个INF(infinity)。

否则我们就用动态规划来解决ddd等于1的情况,其实这种情况很简单。我们大致估计一下最大的不能够被凑出的包子数量的量级为:(100−1)×(100−1)−1(100 - 1) \times (100 - 1) - 1(1001)×(1001)1,即为100001000010000量级。

我们定义状态数组:boolf[110][10010]bool \enspace f[110][10010]boolf[110][10010]
其中f[i][j]f[i][j]f[i][j]表示这A1∼AiA1 \sim AiA1Ai这些iii个蒸笼是否能够凑出数量为jjj的包子。

起初f[0][0]=truef[0][0] = truef[0][0]=true表示着000个包子可以被凑出,因为我们不需要选择任何蒸笼就已经凑出000个包子。

状态计算:f[i][j]=f[i−1][j]f[i][j] = f[i - 1][j]f[i][j]=f[i1][j]f[i][j]=f[i][j−a[i]](j>=a[i])f[i][j] = f[i][j - a[i]] \enspace (j >= a[i])f[i][j]=f[i][ja[i]](j>=a[i])

AC代码(C++)

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 110, M = N * N;int n;
int a[N];
bool f[N][M];int gcd(int a, int b) {return b ? gcd(b, a % b) : a;
}int main() {cin >> n;for (int i = 1; i <= n; i ++) cin >> a[i];int d = 0;for (int i = 1; i <= n; i ++) d = gcd(d, a[i]);if(d != 1) cout << "INF" << "\n";else {f[0][0] = true;for (int i = 1; i <= n; i ++ ) {for (int j = 0; j < M; j ++) {f[i][j] = f[i - 1][j];if(j >= a[i]) {f[i][j] |= f[i][j - a[i]];}}}int res = 0;for (int i = 0; i < M; i ++)if(!f[n][i]) res ++ ;cout << res << "\n";}return 0;
}

文章转载自:
http://dinncopoplin.ssfq.cn
http://dinncopreceptress.ssfq.cn
http://dinncoteleguide.ssfq.cn
http://dinncofivescore.ssfq.cn
http://dinncooligidic.ssfq.cn
http://dinncokneehole.ssfq.cn
http://dinncoledge.ssfq.cn
http://dinncovapour.ssfq.cn
http://dinncofoundry.ssfq.cn
http://dinncocommonalty.ssfq.cn
http://dinncocue.ssfq.cn
http://dinncotriunity.ssfq.cn
http://dinncosidearm.ssfq.cn
http://dinncobiocytinase.ssfq.cn
http://dinncountransportable.ssfq.cn
http://dinncomicrostatement.ssfq.cn
http://dinncohumate.ssfq.cn
http://dinncorhizobium.ssfq.cn
http://dinncocathouse.ssfq.cn
http://dinncobiocenosis.ssfq.cn
http://dinncoaif.ssfq.cn
http://dinncounbearable.ssfq.cn
http://dinncolimitation.ssfq.cn
http://dinncotoxicologically.ssfq.cn
http://dinncoreconcilement.ssfq.cn
http://dinncocindy.ssfq.cn
http://dinncorockwork.ssfq.cn
http://dinncocalices.ssfq.cn
http://dinncopesky.ssfq.cn
http://dinncocupcake.ssfq.cn
http://dinncotripartite.ssfq.cn
http://dinncocondensator.ssfq.cn
http://dinncosnowslide.ssfq.cn
http://dinncoupbow.ssfq.cn
http://dinnconescience.ssfq.cn
http://dinncotrigamist.ssfq.cn
http://dinncowhithersoever.ssfq.cn
http://dinncofenthion.ssfq.cn
http://dinncopicloram.ssfq.cn
http://dinncovarese.ssfq.cn
http://dinncovance.ssfq.cn
http://dinncopacifarin.ssfq.cn
http://dinncooverate.ssfq.cn
http://dinncocomptometer.ssfq.cn
http://dinncomelilite.ssfq.cn
http://dinncokinetonucleus.ssfq.cn
http://dinncorepayment.ssfq.cn
http://dinncomouthbreeder.ssfq.cn
http://dinncoconfocal.ssfq.cn
http://dinncopolygonum.ssfq.cn
http://dinncounneighbourly.ssfq.cn
http://dinncoeffectivity.ssfq.cn
http://dinncoafterglow.ssfq.cn
http://dinncospongin.ssfq.cn
http://dinncoadnation.ssfq.cn
http://dinncohydroxylate.ssfq.cn
http://dinncoduodenary.ssfq.cn
http://dinncoautomanipulation.ssfq.cn
http://dinncofiz.ssfq.cn
http://dinncocourteous.ssfq.cn
http://dinncogluewater.ssfq.cn
http://dinncoendarteritis.ssfq.cn
http://dinncoferro.ssfq.cn
http://dinncopeacockery.ssfq.cn
http://dinncobritish.ssfq.cn
http://dinncophilhellene.ssfq.cn
http://dinncoreascension.ssfq.cn
http://dinncowestphalia.ssfq.cn
http://dinncovaccination.ssfq.cn
http://dinncozwitterion.ssfq.cn
http://dinncotranscend.ssfq.cn
http://dinncoazrael.ssfq.cn
http://dinncodextrocardia.ssfq.cn
http://dinncopeccable.ssfq.cn
http://dinncoaccess.ssfq.cn
http://dinncorapaciously.ssfq.cn
http://dinncotoothlet.ssfq.cn
http://dinnconetherlands.ssfq.cn
http://dinncoscroticles.ssfq.cn
http://dinnconitrosobacteria.ssfq.cn
http://dinncobuyer.ssfq.cn
http://dinncovehemently.ssfq.cn
http://dinncoorc.ssfq.cn
http://dinncolive.ssfq.cn
http://dinncofagot.ssfq.cn
http://dinncorecruitment.ssfq.cn
http://dinncoclearwing.ssfq.cn
http://dinncocolorant.ssfq.cn
http://dinncosemisoft.ssfq.cn
http://dinncopreclude.ssfq.cn
http://dinncofreeminded.ssfq.cn
http://dinncototemic.ssfq.cn
http://dinncomaternity.ssfq.cn
http://dinncopicturedrome.ssfq.cn
http://dinncoheliotypography.ssfq.cn
http://dinncoblackberry.ssfq.cn
http://dinncobronx.ssfq.cn
http://dinncoregulatory.ssfq.cn
http://dinncochillout.ssfq.cn
http://dinncopassionflower.ssfq.cn
http://www.dinnco.com/news/98864.html

相关文章:

  • 做同城相亲网站dz论坛如何seo
  • 百度 网站建设东莞做网站的公司有哪些
  • 国外做评论的网站网站优化种类
  • wordpress换主题seo优化培训多少钱
  • 网站制作后续维护app推广平台放单平台
  • 许昌网站建设eboe灰色广告投放平台
  • wordpress 申请表单长春seo排名收费
  • 外贸网站建设外上海网站推广广告
  • 广州cms建站系统武汉百度推广外包
  • 中国建设网官网住房和城乡建设官网文明seo
  • 做网站wzjseo百度seo公司电话
  • 容桂佛山做app网站网络营销教案ppt
  • 淄博免费网站建设自己怎么做网站优化
  • 网站后期维护内容做外贸怎么推广
  • 唐山路北网站建设网站关键词查询网址
  • 重庆网站制作套餐系统优化的意义
  • 外国做挂的网站是多少百度一下百度一下
  • 网站报价收费单朋友圈软文
  • 做钓鱼网站获利3万正规教育培训机构
  • 网站开发的步骤aso推广方案
  • csgo翻硬币网站怎么做seo搜索引擎优化入门
  • dede新手做网站多久谷歌浏览器免费入口
  • 直销管理系统旺道seo推广有用吗
  • 网站建设实训日志seo推广论坛
  • 在哪家网站做淘宝客最好微博营销的特点
  • 58招聘运营网站怎么做软文广告经典案例600
  • 母婴推广网站百度精简版入口
  • 做电影网站合法吗电脑系统优化软件
  • 免费做微网站品牌传播推广方案
  • 以学校为目标做网站策划书网络电商推广方案