sgu104: Little Shop of Flowers
来源:互联网 发布:淘宝上买的拉卡拉 编辑:程序博客网 时间:2024/06/04 19:15
DP题,并不难。
#include <cstdio>const int maxn = 106;const int oo = 0x3f3f3f3f;inline int read(){ int x = 0, f = 1, t = getchar(); while(t < '0' || t > '9') { if(t == '-') f = -1; t = getchar(); } while(t >= '0' && t <= '9') { x = (x << 1) + (x << 3) + t - '0'; t = getchar(); } return x * f;}int n, m;int a[maxn][maxn];int f[maxn][maxn]; //f[i][j] ---> 第i种花,放到了第j行时的最大美观度 int p[maxn][maxn];void init(){ n = read(), m = read(); for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) a[i][j] = read();}void print(int d, int x){ if(d == 0) return ; print(d-1, p[d][x]); printf("%d", x); if(d < n) putchar(' '); else puts("");}void work(){ for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m-n+i; ++j) { int &r = f[i][j]; r = -oo; for(int k = i-1; k < j; ++k) { if(r < f[i-1][k]) { r = f[i-1][k]; p[i][j] = k; } } if(r != -oo) r += a[i][j]; } } int ans = -oo, x; for(int i = n; i <= m; ++i) { if(ans < f[n][i]) { ans = f[n][i]; x = i; } } printf("%d\n", ans); print(n, x);}int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif init(); work(); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu104:Little Shop of Flowers
- SGU104 Little Shop of Flowers
- sgu104: Little Shop of Flowers
- SGU104 Little shop of flowers
- SGU104 Little Shop of Flowers (DP)
- SGU104 Little shop of flowers(DP)
- SGU104 Little shop of flowers (DP)
- POJ 1157/SGU104 Little shop of flowers(DP)
- LITTLE SHOP OF FLOWERS
- LITTLE SHOP OF FLOWERS
- LITTLE SHOP OF FLOWERS
- LITTLE SHOP OF FLOWERS
- LITTLE SHOP OF FLOWERS
- LITTLE SHOP OF FLOWERS
- LITTLE SHOP OF FLOWERS
- POJ1157 LITTLE SHOP OF FLOWERS
- pku1157 LITTLE SHOP OF FLOWERS
- PKU1157 little shop of flowers
- sgu101: Domino
- 下载的Demo不能使用真机运行
- Program1
- sgu103: Traffic Lights
- json解析使用第三方类库JSONKit
- sgu104: Little Shop of Flowers
- 经典吧_经典传奇
- ubuntu 中文字体安装
- WOT简介
- 关于工资的三个秘密
- Phalcon学习笔记(3)目录结构与命名约定
- json解析NSJSONSerialization方法
- 为什么是kafka(二)
- sgu105: Div 3