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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

[PA 2014]Kuglarz

發布時間:2024/7/19 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [PA 2014]Kuglarz 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

魔術師的桌子上有n個杯子排成一行,編號為1,2,…,n,其中某些杯子底下藏有一個小球,如果你準確地猜出是哪些杯子,你就可以獲得獎品。花費c_ij元,魔術師就會告訴你杯子i,i+1,…,j底下藏有球的總數的奇偶性。
采取最優的詢問策略,你至少需要花費多少元,才能保證猜出哪些杯子底下藏著球?

Input

第一行一個整數n(1<=n<=2000)。
第i+1行(1<=i<=n)有n+1-i個整數,表示每一種詢問所需的花費。其中c_ij(對區間[i,j]進行詢問的費用,1<=i<=j<=n,1<=c_ij<=10^9)為第i+1行第j+1-i個數。

Output

輸出一個整數,表示最少花費。

Sample Input

5
1 2 3 4 5
4 3 2 1
3 4 5
2 1
5

Sample Output

7

題解

求一棵最小生成樹...

1 //It is made by Awson on 2017.10.15 2 #include <set> 3 #include <map> 4 #include <cmath> 5 #include <ctime> 6 #include <cmath> 7 #include <stack> 8 #include <queue> 9 #include <vector> 10 #include <string> 11 #include <cstdio> 12 #include <cstdlib> 13 #include <cstring> 14 #include <iostream> 15 #include <algorithm> 16 #define LL long long 17 #define Min(a, b) ((a) < (b) ? (a) : (b)) 18 #define Max(a, b) ((a) > (b) ? (a) : (b)) 19 #define sqr(x) ((x)*(x)) 20 using namespace std; 21 const int N = 2000; 22 const int INF = ~0u>>1; 23 24 int n, mp[N+5][N+5]; 25 int dist[N+5]; 26 bool vis[N+5]; 27 28 LL Prim() { 29 LL ans = 0; 30 for (int i = 1; i <= n; i++) dist[i] = mp[1][i]; 31 vis[1] = 1; 32 for (int t = 1; t < n; t++) { 33 int loc, minn = INF; 34 for (int i = 1; i <= n; i++) if (!vis[i] && dist[i] < minn) { 35 minn = dist[i], loc = i; 36 } 37 ans += minn; vis[loc] = 1; 38 for (int i = 1; i <= n; i++) dist[i] = Min(dist[i], mp[loc][i]); 39 } 40 return ans; 41 } 42 void work() { 43 scanf("%d", &n); n++; 44 for (int i = 1; i < n; i++) for (int j = i+1; j <= n; j++) scanf("%d", &mp[i][j]), mp[j][i] = mp[i][j]; 45 printf("%lld\n", Prim()); 46 } 47 int main() { 48 work(); 49 return 0; 50 }

?

轉載于:https://www.cnblogs.com/NaVi-Awson/p/7670872.html

總結

以上是生活随笔為你收集整理的[PA 2014]Kuglarz的全部內容,希望文章能夠幫你解決所遇到的問題。

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