349B - Color the Fence

Color the Fence

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya‘s house. Igor thinks that the larger the number is, the more chance to win Tanya‘s heart he has.

Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters of paint. Besides, Igor heard that Tanya doesn‘t like zeroes. That‘s why Igor won‘t use them in his number.

Help Igor find the maximum number he can write on the fence.

Input

The first line contains a positive integer v(0 ≤ v ≤ 106). The second line contains nine positive integers a1, a2, ..., a9(1 ≤ ai ≤ 105).

Output

Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.

Sample Input

Input

55 4 3 2 1 2 3 4 5

Output

55555

Input

29 11 1 12 5 8 9 10 6

Output

33

Input

01 1 1 1 1 1 1 1 1

Output

-1

/*
题意:给你v升染料,有1-9个数字,写每个数字都耗费不同的燃料,问你用这些燃料最多能写出来的数字是多少

#感悟:爆炸,尽然没想起来这么贪,最长的长度肯定cur=v/minv然后,枚举cur位,都尽可能的取一个最大的数

*/

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int a[11];
vector<int> v;
int n;
int minv=INF;
int mini;
int cur;
int main(){
    // freopen("in.txt","r",stdin);
    v.clear();
    scanf("%d",&n);
    for(int i=0;i<9;i++){
        scanf("%d",&a[i]);
        if(a[i]<=minv){
            minv=a[i];
            mini=i;
        }
    }
    cur=n/minv;
    if(cur==0){
        puts("-1");
        return 0;
    }
    int res=0;
    for(int i=0;i<cur;i++){//查找每一位
        for(int j=8;j>=0;j--){
            //每一位都找最大的
            if(n<=minv){
                v.push_back(mini+1);
                break;
            }
            if(a[j]>n) continue;
            if( (n-a[j])/minv+v.size()+1==cur){
                res+=a[j];
                v.push_back(j+1);
                n-=a[j];
                break;
            }
        }
    }
    for(int i=0;i<v.size();i++){
        printf("%d",v[i]);
    }
    printf("\n");
    return 0;
}
时间: 2024-11-08 07:06:13

349B - Color the Fence的相关文章

codeforces 349B Color the Fence 贪心,思维

1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1-9每个字母分别要ai升油漆,问最多可画多大的数字. 贪心,也有点考思维. #include<bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f int main() { int v,a[1

codeforces349B - Color the Fence 贪心+DP

题意:1-9每个字母需要消耗ai升油漆,问你用油漆最多刻意画多大的数字 解题思路: 首先我们要贪心,可以知道我最优是先使我们位数尽可能长,然后才是就是位数长的情况下使得从最高位开始尽可能大.所以要取满足最长位最小的那个数,方便我们DP 解题代码: 1 // File Name: 349b.cpp 2 // Author: darkdream 3 // Created Time: 2014年07月24日 星期四 21时40分13秒 4 5 #include<vector> 6 #include&

南阳oj(nyoj) 791 Color the fence

Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom wants to show his love and write a number on the fence opposite to Mary's house. Tom thinks that the larger the numbers is, the more chance to win Mary's

nyoj 791 Color the fence 【贪心】

Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom wants to show his love and write a number on the fence opposite to Mary's house. Tom thinks that the larger the numbers is, the more chance to win Mary's

nyoj 791——Color the fence——————【贪心】

Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom wants to show his love and write a number on the fence opposite to Mary’s house. Tom thinks that the larger the numbers is, the more chance to win Mary’s

NYOJ-Color the fence

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=791 转载自:http://www.cnblogs.com/windysai/p/3432414.html Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom wants to show his love and write a number on

暑假cf50练之1

Codeforces Round #202 (Div. 2) 第一题水题但是wa了一发,排队记录下收到的25,50,100,看能不能找零,要注意100可以找25*3 复杂度O(n) 第二题贪心,先找出最小的花费,然后就能得出最长的位数,然后循环对每个位上的数看能不能加上剩余的油漆比现在这数大,输出即可 复杂度O(10n) By 2016326603147, contest: Codeforces Round #202 (Div. 2), problem: (B) Color the Fence,

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

题目链接:http://codeforces.com/problemset/problem/448/C ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Leetcode: Paint Fence

There is a fence with n posts, each post can be painted with one of the k colors. You have to paint all the posts such that no more than two adjacent fence posts have the same color. Return the total number of ways you can paint the fence. Note: n an