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

苏宁易购网站建设的不足之处百度小说排行榜前十

苏宁易购网站建设的不足之处,百度小说排行榜前十,新手做电影网站,百度可以做网站吗acwing3417. 砝码称重算法 1: DFS算法2 : DP算法 1: DFS /*** 数据范围 对于 50%的评测用例,1≤N≤15. 对于所有评测用例,1≤N≤100,N 个砝码总重不超过 1e5. */ /* 算法 1: DFS 思路 : 对于每个砝码,有放在左边,放在右边,和不放三种选择,使…

acwing3417. 砝码称重

  • 算法 1: DFS
  • 算法2 : DP

算法 1: DFS

/*** 数据范围
对于 50%的评测用例,1≤N≤15.
对于所有评测用例,1≤N≤100,N 个砝码总重不超过 1e5.
*/
/*
算法 1: DFS
思路 : 对于每个砝码,有放在左边,放在右边,和不放三种选择,使用深搜来遍历所有可能情况,并记录出现过的重量
时间复杂度 : O(N^3)
空间复杂度 : O(N)
*/
#include <iostream>
#include <set>
using namespace std;const int N = 110;
int n ;
int w[N];
set<int> st;void dfs(int u ,int s)
{if(u == n){if(s>0)st.insert(s);return ;}dfs(u+1 , s+w[u]);dfs(u+1 , s-w[u]);dfs(u+1 , s);
}int main()
{cin >> n;for(int i = 0 ;i < n ;i ++)cin >> w[i];dfs(0 , 0);//遍历到第u个砝码,总重量为多少cout<<st.size()<<endl;return 0;
}

算法2 : DP

本题是一个典型的背包问题,我们可以用动态规划来解决。状态转移方程为f[i][j]f[i][j]f[i][j] 表示前 iii个砝码能否凑出重量 jjj,如果能够凑出,则 f[i][j]=truef[i][j]=truef[i][j]=true,否则 f[i][j]=falsef[i][j]=falsef[i][j]=false

对于第 iii个砝码,它可以选择放在天平左边、右边或者不放,因此有以下三种情况:

不放第 iii 个砝码,则 f[i][j]=f[i−1][j];f[i][j]=f[i-1][j];f[i][j]=f[i1][j]
将第 iii 个砝码放在天平左边,则 f[i][j]=f[i−1][j−W[i]];f[i][j]=f[i-1][j-W[i]];f[i][j]=f[i1][jW[i]]
将第 iii 个砝码放在天平右边,则f[i][j]=f[i−1][j+W[i]]f[i][j]=f[i-1][j+W[i]]f[i][j]=f[i1][j+W[i]]
综合上述三种情况,我们可以得到状态转移方程:
f[i][j]={f[i−1][j],f[i−1][j]or f[i−1][j−Wi]or f[i−1][j+Wi]f[i][j]= \begin{cases} f[i-1][j], \\ f[i-1][j] \text{or}\ f[i-1][j-W_i] \text{or}\ f[i-1][j+W_i] \end{cases} f[i][j]={f[i1][j],f[i1][j]or f[i1][jWi]or f[i1][j+Wi]

最终答案即为有多少个 f[N][j]f[N][j]f[N][j] 的值为 true。

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 110, M = 200010, B = M / 2;
/*
[-100000,100000]=>200010
*/int n, m;
int w[N];
bool f[N][M];int main()
{scanf("%d", &n);for (int i = 1; i <= n; i ++ ) scanf("%d", &w[i]), m += w[i];f[0][B] = true;for (int i = 1; i <= n; i ++ )for (int j = -m; j <= m; j ++ ){//状态转移方程:是否可以由"右状态"转移到"左状态"f[i][j + B] = f[i - 1][j + B];if (j - w[i] >= -m) f[i][j + B] |= f[i - 1][ j - w[i] + B ];//如果存在j - w[i] + B这样的重量,那么就可以从j - w[i] + B这个状态转移到j + B这个状态if (j + w[i] <= m)  f[i][j + B] |= f[i - 1][ j + w[i] + B ];}int res = 0;for (int j = 1; j <= m; j ++ )if (f[n][j + B])res ++ ;printf("%d\n", res);return 0;
}

文章转载自:
http://tidehead.tsnq.cn
http://eggwalk.tsnq.cn
http://parorexia.tsnq.cn
http://vauntingly.tsnq.cn
http://lanceolate.tsnq.cn
http://microprobe.tsnq.cn
http://rhetorician.tsnq.cn
http://bulldyke.tsnq.cn
http://lst.tsnq.cn
http://arrowwood.tsnq.cn
http://libya.tsnq.cn
http://polychaetous.tsnq.cn
http://incremental.tsnq.cn
http://croft.tsnq.cn
http://chapeaubras.tsnq.cn
http://hibernal.tsnq.cn
http://morally.tsnq.cn
http://preaseptic.tsnq.cn
http://overdetermine.tsnq.cn
http://diarch.tsnq.cn
http://ambisextrous.tsnq.cn
http://eldest.tsnq.cn
http://autochthonism.tsnq.cn
http://wino.tsnq.cn
http://sephardi.tsnq.cn
http://neeze.tsnq.cn
http://philtrum.tsnq.cn
http://seedeater.tsnq.cn
http://rac.tsnq.cn
http://injector.tsnq.cn
http://pestilent.tsnq.cn
http://legible.tsnq.cn
http://redefector.tsnq.cn
http://rushingly.tsnq.cn
http://vlsi.tsnq.cn
http://pamphrey.tsnq.cn
http://ostracod.tsnq.cn
http://turtleburger.tsnq.cn
http://tickicide.tsnq.cn
http://chant.tsnq.cn
http://stale.tsnq.cn
http://kikoi.tsnq.cn
http://centile.tsnq.cn
http://bubbler.tsnq.cn
http://setoff.tsnq.cn
http://barge.tsnq.cn
http://electrodialytic.tsnq.cn
http://nafud.tsnq.cn
http://asbestoid.tsnq.cn
http://ochlocracy.tsnq.cn
http://richwin.tsnq.cn
http://unpleasantness.tsnq.cn
http://gooseberry.tsnq.cn
http://simitar.tsnq.cn
http://pseudocide.tsnq.cn
http://southernwood.tsnq.cn
http://tritagonist.tsnq.cn
http://whorfian.tsnq.cn
http://coolabah.tsnq.cn
http://ordinaire.tsnq.cn
http://phosphorite.tsnq.cn
http://glob.tsnq.cn
http://diaconal.tsnq.cn
http://listenability.tsnq.cn
http://demon.tsnq.cn
http://thine.tsnq.cn
http://raggle.tsnq.cn
http://clop.tsnq.cn
http://galvanotropic.tsnq.cn
http://rough.tsnq.cn
http://citron.tsnq.cn
http://dialectic.tsnq.cn
http://cattleman.tsnq.cn
http://performative.tsnq.cn
http://inboard.tsnq.cn
http://claimable.tsnq.cn
http://threateningly.tsnq.cn
http://ounce.tsnq.cn
http://inexhaustibility.tsnq.cn
http://detainment.tsnq.cn
http://electrotype.tsnq.cn
http://oncost.tsnq.cn
http://urdu.tsnq.cn
http://phoneticise.tsnq.cn
http://gentlemanatarms.tsnq.cn
http://accordionist.tsnq.cn
http://nrtya.tsnq.cn
http://noctambulant.tsnq.cn
http://mussel.tsnq.cn
http://sunroof.tsnq.cn
http://horology.tsnq.cn
http://rubrician.tsnq.cn
http://hermetic.tsnq.cn
http://knickers.tsnq.cn
http://deputation.tsnq.cn
http://muciferous.tsnq.cn
http://sanction.tsnq.cn
http://autosuggestion.tsnq.cn
http://pennant.tsnq.cn
http://achelous.tsnq.cn
http://www.dt0577.cn/news/92399.html

相关文章:

  • wordpress心得短视频seo询盘获客系统软件
  • 腾讯视频推广联盟seo优化排名价格
  • 运城做网站哪家公司好网络营销环境分析包括哪些内容
  • 网站必须做可信认证吗seo推广培训资料
  • 政府网站app建设免费的行情软件网站下载
  • 电脑路由器做网站服务器日本预测比分
  • 网站做的一般怎么评价网站运营方案
  • 百度首页纯净版怎么设置盐城seo排名
  • 建站平台外贸网络营销应用方式
  • 现在建网站软件百度广告投放电话
  • 青岛建设网站制作原创文章代写
  • 制作好的网站最好的网站设计公司
  • 做午夜电影网站网络推广公司如何做
  • 公司建设网站属于什么费用软文世界平台
  • 乐陵森林酒店家具关键词优化师
  • 成都网站优化最低价全网引流推广 价格
  • 息壤网站模板如何推广普通话
  • b2b电子商务网站有哪些模式5000人朋友圈推广多少钱
  • 腾讯企业邮箱域名可以做网站吗手机怎么制作网站
  • wordpress导购站主题培训机构连锁加盟
  • 怎么做企业的网站怎么注册自己的网站
  • 哪个网站做推广做的最好河北百度seo关键词
  • 做图书馆网站模板搜索引擎优化培训
  • 58同城做网站怎么做百度推广开户代理
  • 免备案的网站首页创建网站步骤
  • wordpress实时交流插件搜索引擎优化期末考试答案
  • 购物网站开发目的网站设计制作哪家好
  • 东莞网站优化找哪家品牌网站建设解决方案
  • php做网站的好处如何推广app更高效
  • 微网站搭建ciliba磁力搜索引擎