P1021 邮票面值设计

暴搜各面值。

  • 剪枝1:面值递增,新面值 \(\in[G_{i-1}+1, n\cdot sum]\). 为什么上界不是 \(n\cdot G_{i-1}+1\) 呢?
  • 剪枝2:\(G_1=1\).

dp 求面值最大值。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int n, k, f[5005], G[17], ans[17], MAX; int calc(int dep, int sum) {
memset(f, 0x3f, sizeof f);
f[0]=0;
for (int i=1; i<=dep; ++i) for (int j=G[i]; j<=sum*n; ++j)
f[j]=min(f[j], f[j-G[i]]+1);
for (int i=1; i<=sum*n; ++i) if (f[i]>n) return i-1;
return sum*n;
} void dfs(int dep, int m, int sum) {
if (dep>k) {
if (MAX<m) {MAX=m; for (int i=1; i<=k; ++i) ans[i]=G[i]; }
return;
}
for (int i=G[dep-1]+1; i<=m+1; ++i) // *1
G[dep]=i, dfs(dep+1, calc(dep, sum+i), sum+i);
} int main() {
scanf("%d%d", &n, &k);
G[1]=1, dfs(2, n, 1); // *2
for (int i=1; i<=k; ++i) printf("%d ", ans[i]);
printf("\nMAX=%d\n", MAX);
return 0;
}

7 August的更多相关文章

  1. Monthly Income Report – August 2016

    原文链接:https://marcoschwartz.com/monthly-income-report-august-2016/ Every month, I publish a report of ...

  2. [ZZ]Sign Up for the First-Ever Appium Roadshow on August 20th in New York City

    http://sauceio.com/index.php/2014/07/appium-roadshow-nyc/?utm_source=feedly&utm_reader=feedly&am ...

  3. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

  4. [转载]ECMA-262 6th Edition / Draft August 24, 2014 Draft ECMAScript Language Specification

    http://people.mozilla.org/~jorendorff/es6-draft.html#sec-23.4 Draft Report Errors and Issues at: htt ...

  5. 135 - ZOJ Monthly, August 2014

    135 - ZOJ Monthly, August 2014 A:构造问题,推断序列奇偶性.非常easy发现最小值不是1就是0.最大值不是n就是n - 1,注意细节去构造就可以 E:dp.dp[i][ ...

  6. git -remote: Support for password authentication was removed on August 13, 2021

    克隆代码时,报错: Support for password authentication was removed on August 13, 2021. Please use a personal ...

  7. August 31st 2016 Week 36th Tuesday

    A friend without faults will never be found. 没有缺点的朋友是永远找不到的. You can't find a friends without faults ...

  8. August 30th 2016 Week 36th Tuesday

    If you keep on believing, the dreams that you wish will come true. 如果你坚定信念,就能梦想成真. I always believe ...

  9. August 29th 2016 Week 36th Monday

    Every has the capital to dream. 每个人都有做梦的本钱. Your vision, our mission. That is an advertisment of UMo ...

  10. August 28th 2016 Week 36th Sunday

    What doesn't kill you makes you stronger. 那些没有彻底击败你的东西只会让你更强大. Where there is life, there is hope, a ...

随机推荐

  1. apicloud地图、即时通讯、人脸识别登录、以及平时踩过得坑

    apicloud技术浅谈 导语 apicloud 的学习也有一段时间了,这是我个人的一些经验,和踩过的坑,希望对大家能有一些帮助. apicloud的知识准备 apicloud 是一个用原生的思想搭建 ...

  2. CentOS修改网络设置,不容易啊,终于可以在virtualbox里上网了

    CentOS 修改网关 修改对应网卡的网关的配置文件[root@centos]# vi /etc/sysconfig/network修改以下内容NETWORKING=yes(表示系统是否使用网络,一般 ...

  3. JavaScript高级程序设计(第3版) 第三章 (基本概念)

    3.1 语法 1.不以数字开头的数字,字母,下划线,美元符号 2.注释:html <!-- --> css/**/ js单行// 多行/**/ 3.ES5 引入了严格模式(strict m ...

  4. 【Python—参数】*arg与**kwargs参数的用法

    在python中,这两个是python中的可变参数,*arg表示任意多个无名参数,类型为tuple;**kwargs表示关键字参数,为dict. # *允许你传入0个或任意个参数,这些可变参数在函数调 ...

  5. Oracle-常见的错误

    1.见下面的例子 create or replace procedure p_qr_stu_cid(s_id in number, c_id out number) as begin select t ...

  6. redis setNx方法

    Redis有一系列的命令,特点是以NX结尾,NX是Not eXists的缩写,如SETNX命令就应该理解为:SET if Not eXists.这系列的命令非常有用,这里讲使用SETNX来实现分布式锁 ...

  7. P5468 [NOI2019]回家路线

    传送门 看题目一眼斜率优化,然后写半天调不出来 结果错误的 $dfs$ 有 $95$ 分?暴力 $SPFA$ 就 $AC$ 了? 讲讲正解: 显然是斜率优化的式子: 先不考虑 $q_{s_k}$ 的贡 ...

  8. NGUI的anchors属性的使用

    一,anchors锚点 我们需要明白target目标的使用,这时是你下面使用left,right,bottom和top的距离,比如我们使用目标为UI Root,这个就是摄像机的视野,所以,我们使用an ...

  9. 微软Visual Studio Code基本特征

    Visual Studio Code它的核心功能还是作为一个代码编辑器.和其他的代码编辑器一样,VScode采取通用的UI和布局,浏览器在左边,显示所有的文件和文件夹,右边你打开的文件的编辑页面. 文 ...

  10. 【彩彩只能变身队(第七组)】Beta版本

    本篇博客包括前期博文汇总.任务墙.团队管理细节与交流细节.代码管理.Beta阶段冲刺.团队总结.用户使用报告.Postmortem报告. 服务器网址:http://47.106.227.154/ 彩彩 ...