【TOJ 4337】Floppy Disk 3.5-inch High Density

描述

The 3.5-inch 1.44 MB  floppy disk is commonly used in 21th century. But 1.44MB is not an accurate statement of a floppy disk's capacity. Actually, because data is recorded on two sides of the disk, each side has 80 tracks, each track has 18 sectors and each sector holds 512 bytes (0.5 KB), So each floppy disk holds 2 * 80 * 18 = 2880 sectors, which total to 2880*0.5KB=1440 KB.
Your job in this problem is to put files onto the 3.5-inch 1.44 MB capacity disk so that there is a minimum amount of unused space left on the floppy disk.

输入

The input data will contain multiple cases.

Each case begins with the an integer, N, the number of files available to go onto the floppy disk, 1 <= N <= 25.

The next N lines, for each case, will contain S, an integer, the size, in kilobytes (KB), of each of the files, 1 <= S <= 1440.

输出

Each case will output the minimum amount of unused space left on the floppy disk per line.

样例输入

5
1000
500
100
150
400

样例输出

40

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x[30],i,j,dp[1445];
    while(cin>>n)
    {
        memset(dp,0,sizeof(dp));
        for(i=1;i<=n;i++)
            scanf("%d",&x[i]);
        for(i=1;i<=n;i++)
            for(j=1440;j>=x[i];j--)
                if(j>=x[i])
                dp[j]=max(dp[j],dp[j-x[i]]+x[i]);

        printf("%d\n",1440-dp[1440]);
    } 
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/kannyi/p/9013587.html