poj 2490 Pimp My Ride
来源:互联网 发布:男人床上粗鲁 知乎 编辑:程序博客网 时间:2024/05/22 08:49
很明显的状态dp。
/* * Author: stormdpzh * Created Time: 2012/8/19 15:21:37 * File Name: poj_2490.cpp */#include <iostream>#include <cstdio>#include <sstream>#include <cstring>#include <string>#include <cmath>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>#include <functional>#define sz(v) ((int)(v).size())#define rep(i, n) for(int i = 0; i < n; i++)#define repf(i, a, b) for(int i = a; i <= b; i++)#define repd(i, a, b) for(int i = a; i >= b; i--)#define out(n) printf("%d\n", n)#define mset(a, b) memset(a, b, sizeof(a))#define wh(n) while(1 == scanf("%d", &n))#define whz(n) while(1 == scanf("%d", &n) && n != 0)#define lint long longusing namespace std;const int INF = 1 << 30;const int MaxN = 16;const int MaxM = (1 << 14) ^ 1;int cost[MaxN][MaxN];int f[MaxN][MaxM];int n;int t;void gao(){ for(int i = 0; i <= n; i++) for(int j = 0; j <= (1 << n); j++) f[i][j] = INF; for(int i = 0; i < n; i++) f[1][1 << i] = cost[i][i]; for(int i = 2; i <= n; i++) for(int j = 0; j < (1 << n); j++) { if(f[i - 1][j] == INF) continue; for(int k = 0; k < n; k++) { if(j & (1 << k)) continue; int id = j | (1 << k); int c = f[i - 1][j] + cost[k][k]; for(int l = 0; l < n; l++) { if(j & (1 << l)) c += cost[k][l]; } f[i][id] = min(f[i][id], c); } }}int main(){ scanf("%d", &t); int ans = 1; while(t--) { scanf("%d", &n); int total = 0; rep(i, n) rep(j, n) scanf("%d", &cost[i][j]); gao(); printf("Scenario #%d:\n", ans++); printf("You have officially been pimped for only $%d\n", f[n][(1 << n) - 1]); puts(""); } return 0;}
- poj 2490 Pimp My Ride
- LightOJ - 1119 Pimp My Ride(状态压缩)
- LightOJ1119-Pimp My Ride-状态dp
- Light oj 1119 - Pimp My Ride(状压dp)
- Light OJ 1119 Pimp My Ride (简单状压DP)
- HOJ 2317 Pimp My Ride(状态压缩DP)
- Light OJ 1119 Pimp My Ride(状压DP)
- 晒晒Pimp My Widgets大赛的优胜作品
- My USACO Analysis:Your Ride Is Here
- USACO1.1.1[My Ride Is Here]
- POJ 1922 Ride to School
- POJ 1922 Ride to School
- POJ 1922 Ride to School
- poj 1922 Ride to School
- poj 1922 Ride to School
- POJ 1922 Ride to School
- POJ:1922 Ride to School
- POJ 3123 Ticket to Ride
- Windows驱动中的设备对象
- USACO section 2.1 Healthy Holsteins(枚举,二进制存储)
- 求最长升序子序列O(nlgn)的算法---HDOJ 1025
- 凸包 基础练习例子(一)
- (Linux,c++)引用
- poj 2490 Pimp My Ride
- JAVA集合小结
- 非官方的gstreamer学习资料及概念摘要
- 2001年3月英语中级口译真题答案及听力原文
- 使用sqldatareader时,获取不到输出参数的值【鸡蛋】
- ubuntu下配置jdk+eclipse+android sdk
- 我的面试经历
- poj 2143 Make a Sequence
- Struts2.3+Spring3.2的整合