租用遊艇問題
阿新 • • 發佈:2018-10-31
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int n; int data[100][100]; int i = 0, j = 0; int k = 0, l = 0;//K要走的站點數量 l是中間站點 int t = 0; scanf("%d",&n); for (i=1; i<n; i++) { for (j=i+1; j<=n; j++) { scanf("%d",&data[i][j]); } } for (k=2; k<n; k++) { for (i=1; i<=n-k; i++) { j = i + k;//起始位置i 終點位置i+k for (l=i+1; l<=j; l++) { t = data[i][l] + data[l][j]; if (t < data[i][j]) { data[i][j] = t; } } } } printf("%d\n",data[1][n]); return 0; }