NOJ [1269] Kha\'Zix\'s Skull

 水题一枚,只是很久没练习背包了,偶尔练练

  • 问题描述
  • Kha'Zix and Rengar are a pair of enemies.
    Rengar can collect a Kha'Zix' Skull after he killed him.

    But you know, every game may appear a Kha'Zix. So Rengar may collect lots of skull.
    Because the shoddy design of Riot, the skull sometimes is big but sometimes small. Rengar's necklace is not too long. He wants to let the necklace leaves as less as possible space.
    Now give you some Kha'Zix' Skull's radius and the length of Rengar's necklace. You should tell Rengar that how much space should Rengar leave?
  • 输入
  • This problem contains several cases.
    The first line of each case contains two integers L and N (0 < L <= 1000, 0 < N <= 1000). Indicate the length of necklace and the number of Kha'Zix' Skulls.
    Then N lines followed. Each line is an integer, indicates the radius of each skull (not exceed 500).
  • 输出
  • For each case, you should the minimum space Rengar should leave for the necklace.


    #include<stdio.h>
    #include<string.h>
    int dp[1010];
    int radius[1010];

    inline int max(int a,int b)
    {
    return a>b?a:b;
    }
    int main()
    {
    int l,n;
    while(~scanf("%d%d",&l,&n))
    {
    memset(dp,0,sizeof(dp));
    int i,j;
    for(i=0;i<n;i++)
    scanf("%d",&radius[i]);
    for(i=0;i<n;i++)
    for(j=l;j>=2*radius[i];j--)
    dp[j]=max(dp[j],dp[j-2*radius[i]]+2*radius[i]);
    printf("%d\n",l-dp[l] );
    }
    return 0;
    }


你可能感兴趣的:(NOJ [1269] Kha\'Zix\'s Skull)