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;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值