/ Vijos / 题库 / Coin /

题解

3 条题解

  • 2
    @ 2016-08-19 16:30:58

    ** 此题首个题解【楼下劲啊】**
    woc我的RP+++++我这蒟蒻竟然2次AC了!!!!!
    doc巨神试了那么多次啊、、我不相信我的眼睛23333
    ```
    测试数据 #0: Accepted, time = 15 ms, mem = 4472 KiB, score = 10
    测试数据 #1: Accepted, time = 218 ms, mem = 4468 KiB, score = 10
    测试数据 #2: Accepted, time = 250 ms, mem = 4472 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 4472 KiB, score = 10
    测试数据 #4: Accepted, time = 281 ms, mem = 4472 KiB, score = 10
    测试数据 #5: Accepted, time = 218 ms, mem = 4468 KiB, score = 10
    测试数据 #6: Accepted, time = 359 ms, mem = 4468 KiB, score = 10
    测试数据 #7: Accepted, time = 109 ms, mem = 4468 KiB, score = 10
    测试数据 #8: Accepted, time = 109 ms, mem = 4468 KiB, score = 10
    测试数据 #9: Accepted, time = 390 ms, mem = 4468 KiB, score = 10

    Accepted, time = 1964 ms, mem = 4472 KiB, score = 100

    然而我毕竟还是个沙茶,想不出正解,只能用外门邪道【当然不是cheat】
    当m很大很大的时候,贪心的正确率很高很高(因为很少出现为了那么一点点更完美而不用最大的)
    所以我当m>1000000的时候就只用最大的,用dp处理m <= 1000000,然后就A了2333
    c++
    #include <bits/stdc++.h>
    using namespace std;

    int a[105], n;
    int dp[1000005];
    int main()
    {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
    memset(dp, 127, sizeof dp);
    dp[0] = 0;
    sort(a+1, a+n+1);
    for (int i = 1; i <= 1000000; i++)
    for (int j = 1; j <= n; j++)
    if (i-a[j] >= 0)
    dp[i] = min(dp[i], dp[i-a[j]]+1);
    long long m;
    int t;
    scanf("%d", &t);
    for (; t--;) {
    scanf("%lld", &m);
    long long ans = 0;
    if (m >= 1000000) {
    ans = (m-1000000)/a[n]+1;
    m -= ans*(long long)a[n];
    }
    //cout << (dp[m]>1000000) << endl;
    ans += dp[m];
    if (dp[m] > 1000000)
    puts("-1");
    else
    printf("%lld\n", ans);
    }
    return 0;
    }

  • 0
    @ 2016-08-27 10:30:05

    测试数据 #0: Accepted, time = 93 ms, mem = 157112 KiB, score = 10
    测试数据 #1: Accepted, time = 328 ms, mem = 157116 KiB, score = 10
    测试数据 #2: Accepted, time = 171 ms, mem = 157112 KiB, score = 10
    测试数据 #3: Accepted, time = 140 ms, mem = 157112 KiB, score = 10
    测试数据 #4: Accepted, time = 515 ms, mem = 157112 KiB, score = 10
    测试数据 #5: Accepted, time = 421 ms, mem = 157112 KiB, score = 10
    测试数据 #6: Accepted, time = 609 ms, mem = 157112 KiB, score = 10
    测试数据 #7: Accepted, time = 281 ms, mem = 157112 KiB, score = 10
    测试数据 #8: Accepted, time = 250 ms, mem = 157112 KiB, score = 10
    测试数据 #9: Accepted, time = 953 ms, mem = 157116 KiB, score = 10
    5次AC 而且过得好WS 23333333
    歪门邪道就是正解

  • -2
    @ 2016-01-10 18:26:06

    虽然我没有AC但我来抢个沙发

  • 1

信息

ID
1861
难度
7
分类
(无)
标签
递交数
149
已通过
30
通过率
20%
被复制
2
上传者