zoukankan      html  css  js  c++  java
  • 12563 Jin Ge Jin Qu hao

    • Don’t sing a song more than once (including Jin Ge Jin Qu).
    • For each song of length t, either sing it for exactly t seconds, or don’t sing it at all.
    • When a song is finished, always immediately start a new song.

    每首歌唱一次,在一定时间类,要求唱歌数量尽量多,时间尽量长。而且在最后一首唱完前,KTV不会停。

    因此找出t-1时间内唱歌数最多为多少,再加上金曲的即可。(感觉思路一样,但就是一直不过   - - !!心塞塞)

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int V[55], num[10000], t, n;
    
    int main()
    {
        int cas, tmp;
        scanf("%d", &cas);
        for(int k = 1; k <= cas; ++k)
        {
            memset(num, 0x8f, sizeof(num));
            scanf("%d%d", &n, &t);
            for(int i = 0; i < n; ++i) scanf("%d", &V[i]);
            num[0] = 0;    //其余初始化为负,使其从0开始计时
            for(int i = 0; i < n; ++i)
                for(int j = t - 1; j >= V[i]; --j)
                    num[j] = max(num[j], num[j - V[i]] + 1);
            tmp = t-1;
            for(int j= t - 1; j >= 0; --j)
                if(num[j] > num[tmp])  //找出数量最大的,并且还能满足时间尽可能长
                    tmp = j;
            printf("Case %d: %d %d
    ", k, num[tmp] + 1, tmp + 678);//再加上金曲
        }
        return 0;
    }
     
    

      

  • 相关阅读:
    Chapter 12 homework
    copy construction note
    Chapter 11 homework
    数组排序最大元素
    temporary Object and destructor
    strcpy() 函数注意的地方
    结对项目第二次作业
    结队项目——第一次作业
    软件工程实践2017第二次作业
    软件工程实践2017第一次作业
  • 原文地址:https://www.cnblogs.com/Przz/p/5409840.html
Copyright © 2011-2022 走看看