程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> zoj2972 Hurdles of 110m

zoj2972 Hurdles of 110m

編輯:C++入門知識

#include <stdio.h>   
#include <string.h>   
#define min(a,b)  a<b  ?  a:b   
  
const int maxn = 115;  
const int INF = 1000000000;  
int f[maxn][maxn];//f[i][j]表示第i個階段耗費j點力量時,的最小耗時。   
  
int main()  
{  
    int i, j, t, n, m, t1, t2, t3, f1, f2;  
    scanf("%d", &t);  
    while (t--) {  
        scanf("%d%d", &n, &m);  
        for (i = 0; i <= n; i++)  
            for (j = 0; j <= m; j++)  
                f[i][j] = INF;  
        f[0][m]  = 0;  
        for (i = 1; i <= n; i++) {  
            scanf("%d%d%d%d%d", &t1, &t2, &t3, &f1, &f2);  
            for (j = 0; j <= m; j++) {  
                if (j >= f1)  
                    f[i][j - f1] = min(f[i][j - f1], f[i - 1][j] + t1);  
                f[i][j] = min(f[i][j], f[i - 1][j] + t2);  
                if (j + f2 <= m)  
                    f[i][j + f2] = min(f[i][j + f2], f[i - 1][j] + t3);  
                else  
                    f[i][m] = min(f[i][m], f[i - 1][j] + t3);  
            }  
        }  
  
        int minn = INF;  
        for (i = 0; i <= m; i++)  
            if (f[n][i] < minn) minn = f[n][i];  
        printf("%d\n", minn);  
    }  
    return 0;  
}  

#include <stdio.h>
#include <string.h>
#define min(a,b)  a<b  ?  a:b

const int maxn = 115;
const int INF = 1000000000;
int f[maxn][maxn];//f[i][j]表示第i個階段耗費j點力量時,的最小耗時。

int main()
{
    int i, j, t, n, m, t1, t2, t3, f1, f2;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &m);
        for (i = 0; i <= n; i++)
            for (j = 0; j <= m; j++)
                f[i][j] = INF;
        f[0][m]  = 0;
        for (i = 1; i <= n; i++) {
            scanf("%d%d%d%d%d", &t1, &t2, &t3, &f1, &f2);
            for (j = 0; j <= m; j++) {
                if (j >= f1)
                    f[i][j - f1] = min(f[i][j - f1], f[i - 1][j] + t1);
                f[i][j] = min(f[i][j], f[i - 1][j] + t2);
                if (j + f2 <= m)
                    f[i][j + f2] = min(f[i][j + f2], f[i - 1][j] + t3);
                else
                    f[i][m] = min(f[i][m], f[i - 1][j] + t3);
            }
        }

        int minn = INF;
        for (i = 0; i <= m; i++)
            if (f[n][i] < minn) minn = f[n][i];
        printf("%d\n", minn);
    }
    return 0;
}






 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved