日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

递推DP UVA 590 Always on the run

發(fā)布時(shí)間:2025/3/21 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 递推DP UVA 590 Always on the run 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

題目傳送門

題意:題意難懂,就是一個(gè)小偷在m天內(nèi)從城市1飛到城市n最小花費(fèi),輸入的是每個(gè)城市飛到其他城市的航班。

分析:dp[i][j] 表示小偷第i天在城市j的最小花費(fèi)。狀態(tài)轉(zhuǎn)移方程:dp[i][j] = min (dp[i-1][k] + cost[k][j][t%day]) t表示在t天時(shí)k飛往j的飛機(jī)的花費(fèi)

收獲:

?

代碼:

/************************************************ * Author :Running_Time * Created Time :2015-8-29 14:07:43 * File Name :UVA_590.cpp************************************************/#include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std;#define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int dp[1010][12]; int d[12][12]; int cost[12][12][32];int main(void) {int n, m, cas = 0;while (scanf ("%d%d", &n, &m) == 2) {if (n == 0 && m == 0) break;for (int i=1; i<=n; ++i) {for (int j=1; j<=n; ++j) {if (i != j) {scanf ("%d", &d[i][j]);for (int k=0; k<d[i][j]; ++k) {scanf ("%d", &cost[i][j][k]);}}}}memset (dp, INF, sizeof (dp));for (int i=2; i<=n; ++i) {if (cost[1][i][0]) {dp[0][i] = cost[1][i][0];}}for (int i=1; i<m; ++i) {for (int k=1; k<=n; ++k) {for (int j=1; j<=n; ++j) {if (j != k) {int c = cost[j][k][i%d[j][k]];if (c) dp[i][k] = min (dp[i][k], dp[i-1][j] + c);}}}}int ans = dp[m-1][n];printf("Scenario #%d\n", ++cas);if(ans != INF){ printf("The best flight costs %d.\n\n", ans); }else{ puts("No flight possible.\n"); } }return 0; }

  

轉(zhuǎn)載于:https://www.cnblogs.com/Running-Time/p/4773806.html

總結(jié)

以上是生活随笔為你收集整理的递推DP UVA 590 Always on the run的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。