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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVA 1025 A Spy in the Metro DP水题

發布時間:2023/12/9 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVA 1025 A Spy in the Metro DP水题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡單DAG,每個狀態有三種決策,原地傻等,上往左開的車,上往右開的車。

#include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <vector> #include <string> #include <queue> #include <deque> #include <bitset> #include <list> #include <cstdlib> #include <climits> #include <cmath> #include <ctime> #include <algorithm> #include <stack> #include <sstream> #include <numeric> #include <fstream> #include <functional>using namespace std;#define MP make_pair #define PB push_back typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef pair<int,int> pii; const int INF = INT_MAX / 3; const double eps = 1e-8; const LL LINF = 1e17; const double DINF = 1e60; const int maxn = 55; const int maxt = 400; int f[maxt][maxn], N, T; int cost[maxn], M1, M2, d1[maxn], d2[maxn]; bool left_bus[maxn][maxt], right_bus[maxn][maxt];int main() {int kase = 1;while(scanf("%d",&N), N) {memset(f,0x3f,sizeof(f));memset(cost,0,sizeof(cost));memset(left_bus,0,sizeof(left_bus));memset(right_bus,0,sizeof(right_bus));int inf = f[0][0];scanf("%d",&T);for(int i = 1;i < N;i++) scanf("%d",&cost[i]);scanf("%d",&M1);for(int i = 1;i <= M1;i++) scanf("%d",&d1[i]);scanf("%d",&M2);for(int i = 1;i <= M2;i++) scanf("%d",&d2[i]);for(int i = 1;i <= M1;i++) {int nowtime = d1[i];for(int j = 1;j <= N;j++) {left_bus[j][nowtime] = true;nowtime += cost[j];}}for(int i = 1;i <= M2;i++) {int nowtime = d2[i];for(int j = N;j >= 1;j--) {right_bus[j][nowtime] = true;nowtime += cost[j - 1];}}f[0][1] = 0;for(int i = 0;i <= T;i++) {for(int j = 1;j <= N;j++) {//waitf[i + 1][j] = min(f[i + 1][j],f[i][j] + 1);//go left_busif(right_bus[j][i] && j > 1 && i + cost[j - 1] <= T) {f[i + cost[j - 1]][j - 1] = min(f[i + cost[j - 1]][j - 1],f[i][j]);}//go right_busif(left_bus[j][i] && j < N && i + cost[j] <= T) {f[i + cost[j]][j + 1] = min(f[i + cost[j]][j + 1],f[i][j]);}}}printf("Case Number %d: ",kase++);if(f[T][N] == inf) puts("impossible");else printf("%d\n",f[T][N]);}return 0; }

  

轉載于:https://www.cnblogs.com/rolight/p/3966017.html

總結

以上是生活随笔為你收集整理的UVA 1025 A Spy in the Metro DP水题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。