[IOI 1998] Polygon
[题目链接]
http://poj.org/problem?id=1179
[算法]
区间DP
[代码]
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 55
const long long INF = 1e15; int i,j,k,l,r,n;
long long num[MAXN<<];
long long mn[MAXN<<][MAXN<<],mx[MAXN<<][MAXN<<];
long long ans;
char op;
char opt[MAXN<<]; int main()
{
scanf("%d",&n);
getchar();
for (i = ; i <= n; i++)
{
if (i > ) scanf(" %c",&op);
else scanf("%c",&op);
scanf("%lld",&num[i]);
opt[i] = opt[i + n] = (op == 't');
num[i+n] = num[i];
}
for (i = ; i <= * n; i++)
{
for (j = i + ; j <= * n; j++)
{
mx[i][j] = -INF;
mn[i][j] = INF;
}
}
for (i = ; i <= * n; i++) mx[i][i] = mn[i][i] = num[i];
for (i = ; i <= n; i++)
{
for (l = ; l <= * n - i + ; l++)
{
r = l + i - ;
for (k = l; k < r; k++)
{
if (opt[k+])
{
mn[l][r] = min(mn[l][r],mn[l][k] + mn[k+][r]);
mx[l][r] = max(mx[l][r],mx[l][k] + mx[k+][r]);
} else
{
mn[l][r] = min(mn[l][r],min(mx[l][k] * mx[k+][r],(mx[l][k] * mn[k+][r],mn[l][k] * mx[k+][r])));
mx[l][r] = max(mx[l][r],max(mx[l][k] * mx[k+][r],mn[l][k] * mn[k+][r]));
}
}
}
}
for (i = ; i <= n; i++) ans = max(ans,mx[i][i+n-]);
printf("%lld\n",ans);
for (i = ; i <= n; i++)
{
if (mx[i][i+n-] == ans)
printf("%d ",i);
}
printf("\n"); return ;
}
[IOI 1998] Polygon的更多相关文章
- 【IOI 1998】 Picture
[题目链接] 点击打开链接 [算法] 线段树扫描线求周长并 [代码] #include <algorithm> #include <bitset> #include <c ...
- poj 1179 Polygon
http://poj.org/problem?id=1179 Polygon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1179 IOI1998 Polygon
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5472 Accepted: 2334 Description Polyg ...
- poj1179 Polygon【区间DP】
Polygon Time Limit: 1000MS Memory Limit: 10000K Total Submissions:6633 Accepted: 2834 Descriptio ...
- 常规DP专题练习
POJ2279 Mr. Young's Picture Permutations 题意 Language:Default Mr. Young's Picture Permutations Time L ...
- DP中环形处理 +(POJ 1179 题解)
DP中环形处理 对于DP中存在环的情况,大致有两种处理的方法: 对于很多的区间DP来说,很常见的方法就是把原来的环从任意两点断开(注意并不是直接删掉这条边),在复制一条一模一样的链在这条链的后方,当做 ...
- HDU 1828 扫描线(矩形周长并)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 1828 Picture(线段树 || 普通hash标记)
http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others) Mem ...
- 【HDU 1828】 Picture (矩阵周长并,线段树,扫描法)
[题目] Picture Problem Description A number of rectangular posters, photographs and other pictures of ...
随机推荐
- A - A Compatible Pair
Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...
- getElementsByName使用
查了下手册,getElementsByName()不能提取没有name属性的标签.div标签本身没有name属性,所以不能被提取.有name标签的主要是各种input标签,所以默认情况下getElem ...
- 使用C#正则表达式获取必应每日图片地址
微软的Bing搜索引擎首页每天都会提供了一些有趣的图片,下面使用正则表达式获取图片的地址,不管是在手机app还是在网站上都是很好的图片素材,而且每天更新,非常不错. 首先访问微软的API,该地址返回的 ...
- C-概览
1.贝尔实验室的Dennis Ritchie在1972年开发了C语言,C来自于Ken Thompson的B语言.当时Ritchie正与 Thompson一起设计UNIX操作系统. 2.C是面向过程的编 ...
- 强连通分量的模版 Kosaraju+Tarjan+Garbow
PS:在贴出代码之前,我得说明内容来源——哈尔滨工业大学出版的<图论及应用>.虽然有一些错误的地方,但是不得不说是初学者该用的书. 从效率的角度来说,Kosaraju <Tarjan ...
- element-ui Cascader 级联选择器示例
<html> <head>test</head> <style> @import url("http://unpkg.com/element- ...
- Nagios Windows客户端NSClient++ 0.4.x安装配置
NSClient++ 0.3.x和NSClient++ 0.4.x的配置完全不一样,官方的文档也没有全部更新.我记录下自己的一些操作. 一.下载安装NSClient++ 1.到http://nsc ...
- Xcode8 NSLog打印json不完整的解决方案
解决方案:自定义宏,通过fprintf函数打印log,完美解决! #ifdef DEBUG #define NSLog(FORMAT, ...) fprintf(stderr, "%s:%z ...
- ORACLE 11g 导出数据
ORACLE 11g 导出 表的时候 不会导出空表 导出空表操作步骤 :(使用PLSQL) 1.打开SQL window 执行下面的 SQL Select 'alter table '||table_ ...
- Java中类的定义
成员变量:对应事物的属性 成员方法:对应事物的行为 类定义的格式 定义类:就是定义类的成员,包括成员变量和成员方法 成员变量:和以前定义变量几乎是一样的.只不过位置发生了改变.在类中,方法外. 成员方 ...