美文网首页
20170909_hdu1158

20170909_hdu1158

作者: zhaohaoying | 来源:发表于2017-09-09 22:53 被阅读0次
    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cstring>
    
    using namespace std;
    
    int aa[105];
    int a,b,c;
    int dp[105][105];
    
    
    int main() {
        int n;
        while(scanf("%d",&n) != EOF && n) {
            int max = 0;
            int min = 0x3f3f3f3f;
            memset(aa,0x3f3f3f3f,sizeof(aa));
            memset(dp,0x3f3f3f3f,sizeof(dp));
            cin >> a >> c >> b;
            for(int i = 1; i <= n; ++i) {
                cin >> aa[i];
                if(max < aa[i])
                    max = aa[i];
                if(min > aa[i])
                    min = aa[i];
            }
            dp[0][min] = min*a;
            for(int i = 1; i <= n; ++i) {
                for(int j = aa[i]; j <= max; ++j) {
                    int t = 0x3f3f3f3f;
                    for(int k = min; k <= max; ++k) {
                        if(k >= j) {
                            int temp = dp[i-1][k] + (k-j)*b + c*j;
                            if(t > temp)
                                t = temp;
                        }
                        else {
                            int temp = dp[i-1][k] + (j-k)*a + c*j;
                            if(t > temp)
                                t = temp;
                        }
                    }
                    dp[i][j] = t;
                }
                
            }
            int mmm = 0x3f3f3f3f;
            for(int i = aa[n]; i <= max; i++) {
                if(dp[n][i] < mmm)
                    mmm = dp[n][i];
            }
            cout << mmm << endl;
        }
        
    }
    

    相关文章

      网友评论

          本文标题:20170909_hdu1158

          本文链接:https://www.haomeiwen.com/subject/kqoajxtx.html