16ms 解法:

#include <cstdio>

//using namespace std;

int data[][];
int dp[][];
int row_min[];
int row_max[]; int n,min,max; void solve(int row) {
int i,j,pos,tmp, tmp_max;
if (row == n) {
max = dp[n-][];
for (i = ; i < n; i++) {
if (max < dp[n-][i]) {
max = dp[n-][i];
}
}
if (min > max) {
min = max;
}
return;
} //prune, the above max value + current line min value > current answer min, then return
if (row_max[row-]+row_min[row]>min) {
return;
} for(i = ; i < n; i++) { //tmp_max cal current row's dp max value
tmp_max = -; for (j = ; j < n; j++) {
tmp = i+j;
pos = tmp < n ? tmp : tmp-n;
dp[row][pos] = dp[row-][pos] + data[row][j]; if (dp[row][pos] > tmp_max) {
tmp_max = dp[row][pos];
}
}
row_max[row] = tmp_max; solve(row+);
} } int main() { int i,j,val,mymin,mymax; while(scanf("%d", &n) && n != -) { for (i = ; i < n; i++) {
mymin = ;
for (j = ; j < n; j++) {
scanf("%d", &val);
data[i][j] = val;
if (val < mymin) {
mymin = val;
}
}
row_min[i] = mymin; //cal min value for every row
} mymax = -;
for (i = ; i < n; i++) {
dp[][i] = data[][i];
if (data[][i] > mymax) {
mymax = data[][i];
}
}
row_max[] = mymax; //first row's max value min = ;
solve(); printf("%d\n", min); }
return ; }

POJ 2078的更多相关文章

  1. POJ 2078 Matrix

    Matrix Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 3239   Accepted: 1680 Descriptio ...

  2. 【POJ - 2078】Matrix(dfs)

    -->Matrix Descriptions: 输入一个n×n的矩阵,可以对矩阵的每行进行任意次的循环右移操作,行的每一次右移后,计算矩阵中每一列的和的最大值,输出这些最大值中的最小值. Sam ...

  3. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  4. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  5. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  6. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  7. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  8. POJ题目分类(转)

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. hammer.js使用

    手势包括点击(tap),长按(press),滑动(swipe),方向(pan) 使用实例: <!DOCTYPE html> <html> <head> <me ...

  2. jQuery5事件相关

    一.注册事件的方式 1.直接注册事件 $(this).事件名(动作函数)://$(this).click(fucntion(){//动作代码}); 2.bind同时给一个对象注册多个事件 $(this ...

  3. Nginx 的常用命令

    nginx命令,先来一波基本操作: start nginx // 启动Nginx nginx -t // 测试配置文件 nginx -v // 查看Nginx版本 nginx -V // 查看Ngin ...

  4. js 设置缓存

    长期存储    localStorage.getItem("key");       //获取键的值    localStorage.setItem("key" ...

  5. jeecms 前台拦截器的研究与改造

    jeecms 前台拦截器的研究与改造 2013年12月24日 15:23:35 xinfei0803 阅读数 3511   jeecms出发点是面向大众的,具有前台开发性,也就是说,即时是未登录(游客 ...

  6. 2019.10.28 csp-s模拟测试91 反思总结

    有一场没一场的233 T1: 胡乱分析一下题意,发现和为n的x个正整数,不同的数字种类不会超过√n个.假设这x个数字都不同,最多也就是(x+1)*x/2=n. 所以可以维护现有的size值以及对应的数 ...

  7. 基于PHP的一种Cache回调与自动触发技术

    $s = microtime(true); for($i=0; $iaaa($array, $array, $array); $data = a::bbb($array, $array, $array ...

  8. stream的filter用法

    Person p1 = new Person("张三", new BigDecimal("23.0"));Person p2 = new Person(&quo ...

  9. TZ_06_SpringMVC_传统文件上传和SpringMVC文件上传方式

    1.传统文件上传方式 <!-- 文件上传需要的jar --> <dependency> <groupId>commons-fileupload</groupI ...

  10. CentOS7 下的 firewall 用法

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...