【链接】 我是链接,点我呀:)

【题意】

让你组成一个只由1~9组成的数字
每个数字需要的paint数字给定。
让你组成一个最大的数字,且所有数字的paint的总和不超过v.

【题解】

先求出a中的最小值mi
最后的长度显然就是a/mi啦
然后从高位到低位,优先让高位优先选择大的数字就好.
(判断这一位能否为i的条件就是,后面的所有位置全都选择mi
看看会不会超过剩余的paint数量就好

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = 10;
static int L = (int)1e6;
static class Task{ int v,mi;
int a[],b[]; public void dfs(int dep,int rest) {
if (dep==0) return;
for (int i = 9;i >= 1;i--) {
if (rest-a[i]-(dep-1)*mi>=0) {
b[dep] = i;
dfs(dep-1,rest-a[i]);
return;
}
}
}
public void solve(InputReader in,PrintWriter out) {
a = new int[N+10];
b = new int[L+10];
v = in.nextInt();
for (int i = 1;i <= 9;i++) a[i] = in.nextInt();
mi = a[1];
for (int i = 1;i <= 9;i++) mi = Math.min(a[i], mi);
int len = v/mi;
if (len==0)
out.println(-1);
else {
dfs(len,v);
for (int i = len;i >= 1;i--) out.print(b[i]);
}
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 349B】Color the Fence的更多相关文章

  1. 【Codeforces 1132C】Painting the Fence

    Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 234F】Fence

    [题目链接]:http://codeforces.com/problemset/problem/234/F [题意] 你有n块板要凃油漆; 然后每块板有高度h[i];(宽度都为1) 然后每块板只能凃同 ...

  4. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【47.95%】【codeforces 554C】Kyoya and Colored Balls

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 758B】Blown Garland

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

随机推荐

  1. Android连接热点的Socket文件传输

    最近把测试丢过来的种种BUG解决后,终于有时间去研究研究Socket通信,再加上以前做的WiFi连接和热点开启,于是有了现在的这篇博文:创建热点发送文件,让另一台手机连接热点接收文件. 效果图: 两台 ...

  2. SQL SERVER 语句大全

    ·SQL的简单查询实例教程关键词:SQL语句大全 中文网 整理编辑,经典SQL语句大全(SQL语句大总结),欢迎网友投稿 下列语句部分是Mssql语句,不可以在access中使用.SQL分类:DDL— ...

  3. bzoj4889

    http://www.lydsy.com/JudgeOnline/problem.php?id=4889 人傻常数大 bzoj上跑不过 洛谷上能过两到三个点 我写的是树套树啊 怎么跑的比分块还慢 每次 ...

  4. 腾讯云linux服务器安装lnmp一键包

    这边域名已经实名了. 然后修改DNS服务器 然后备案吧 还是先不备案,直接云解析DNS 哦,想起来了,阿里云自己都可以生成SSL证书.重新弄一次吧,其实腾讯云也可以申请域名型免费版DV

  5. 使用display:flex;实现垂直水平居中

    body,div{margin:0px;padding:0px;} .flex-container{display:flex;height:300px;background-color:#ddd;ju ...

  6. 【WIP】Bootstrap 基础

    创建: 2017/09/28   更新: 2017/10/14 标题加上[WIP]

  7. 拼接html 的事件转义

    attach += "<div style='line-height: 10px;float: left;margin-left: 10px;' id='attach_" + ...

  8. Win32子窗口的创建

    本文主要是在一个主窗口下创建一个子窗口.主窗口有一个菜单,菜单下只有设置一个选项,点击设置选项,弹出设置界面,点击设置界面关闭则关闭.我在开发的时候遇到两个问题,第一就是一点设置关闭就整个应用都关了, ...

  9. JS——sort

    1.a-b升序 <script> var arr = [2, 3, 1, 5, 0]; function compare(a, b) { return a - b; } console.l ...

  10. html——ico

    下载: 网址+/favicon.ico 引用: 1.<link href="favicon.ico" rel="icon" /> 2.<lin ...