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. Vue事件总线

    一 项目结构 二 main.js import Vue from "vue"; import App from "./App.vue"; import Tool ...

  2. 逻辑回归提高阈值对p和r的影响

    这里我做了一个实验 也就是随着阈值的增大,precision增加或者不变,recall减少或者不变.

  3. 微信小程序开发项目过程中的一个要注意事项

    在微信小程序开发过程中,有时候会用到常用的一些特殊字符如:‘<’.‘>’.‘&’.‘空格’等,微信小程序同样支持对转义字符的处理, decode属性默认为false,不会解析我们的 ...

  4. jvm性能监控(5)-jdk自带工具 VisualVM

    一.在服务器的jdk的bin目录下添加配置文件 jstatd.all.policy [root@localhost /]# cd /usr/local/src/jdk1.8.0_131/bin/ [r ...

  5. 小Z的袜子(题解)(莫队)

    小Z的袜子(题解)(莫队) Junlier良心莫队 题目 luoguP1494 [国家集训队]小Z的袜子 code #include<bits/stdc++.h> #define lst ...

  6. Springboot消除switch-case方法

    Springboot消除switch-case方法 背景 最近,在使用springboot开发一个接口的时候,需要根据接收的请求事件类型,去执行不同的操作,返回不同的结果,基本逻辑如下: String ...

  7. 73.Largest Rectangle in Histogram(最大矩形)

    Level:   Hard 题目描述: Given n non-negative integers representing the histogram's bar height where the ...

  8. 246-基于TI DSP TMS320C6678、Altera FPGA的CPCI处理卡

    基于TI DSP TMS320C6678.Altera FPGA的CPCI处理卡 1.板卡概述  本板卡由我公司自主研发,基于CPCI架构,符合CPCI2.0标准,采用两片TI DSP TMS320C ...

  9. JVM内存组成

    JVM的内存区域模型 1.方法区 也称永久代.非堆. 用于存储虚拟机加载的类信息.常量.静态变量,是各个线程共享的内存区域. 默认最小值为16MB,最大值为64MB,可以通过-XX:PermSize和 ...

  10. 新装ubantu 18.04(自用)

    1.下载镜像,制作u盘启动,装机,分区(具体的百度) 2.sudo passwd root     给root用户创建密码 3.解压tar.gz文件 sudo tar -zxvf  pycharm.t ...