uva10163 Storage Keepers

Posted lqerio

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva10163 Storage Keepers相关的知识,希望对你有一定的参考价值。

习题9-9

 

注意前提是最小值最大。很少做两次dp的题。

 

初始化要细心。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

const int INF = 0x3f3f3f3f;
int n, m;
int f[110][110], g[110][110];
int p[35];

int main(){

    while(~scanf("%d%d", &n, &m) && n+m){

        for(int i=1; i<=m; ++i)
            scanf("%d", &p[i]);

        memset(f, 0, sizeof(f));

        for(int i=1; i<=m; ++i){
            f[i-1][0] = INF;
            for(int j=1; j<=n; ++j){
                f[i][j] = f[i-1][j];
                for(int k=1; k<=j; ++k){
                    f[i][j] = max(f[i][j], min(f[i-1][j-k], p[i]/k));
                }
            }
        }

        memset(g, INF, sizeof(g));

        for(int i=1; i<=m; ++i){
            g[i-1][0] = 0;
            for(int j=1; j<=n; ++j){
                g[i][j] = g[i-1][j];
                for(int k=1; k<=j; ++k){
                    int s = p[i]/k;
                    if(s >= f[m][n]){
                        g[i][j] = min(g[i][j], g[i-1][j-k]+p[i]);
                    }
                }
            }
        }

        printf("%d %d
", f[m][n], f[m][n]==0?0:g[m][n]);
    }
    return 0;
}

 

以上是关于uva10163 Storage Keepers的主要内容,如果未能解决你的问题,请参考以下文章

UVA 10163 - Storage Keepers

javascript Finders Keepers

Finders Keepers

Finders Keepers

FCC 中级算法题 Finders Keepers

浏览器浏览器存储&缓存 - Cookie - localStorage - sessionStorage - IndexDB - Cache Storage - Application C(代