[题目链接]

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的更多相关文章

  1. 【IOI 1998】 Picture

    [题目链接] 点击打开链接 [算法] 线段树扫描线求周长并 [代码] #include <algorithm> #include <bitset> #include <c ...

  2. poj 1179 Polygon

    http://poj.org/problem?id=1179 Polygon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  3. POJ 1179 IOI1998 Polygon

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5472   Accepted: 2334 Description Polyg ...

  4. poj1179 Polygon【区间DP】

    Polygon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:6633   Accepted: 2834 Descriptio ...

  5. 常规DP专题练习

    POJ2279 Mr. Young's Picture Permutations 题意 Language:Default Mr. Young's Picture Permutations Time L ...

  6. DP中环形处理 +(POJ 1179 题解)

    DP中环形处理 对于DP中存在环的情况,大致有两种处理的方法: 对于很多的区间DP来说,很常见的方法就是把原来的环从任意两点断开(注意并不是直接删掉这条边),在复制一条一模一样的链在这条链的后方,当做 ...

  7. HDU 1828 扫描线(矩形周长并)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. hdu 1828 Picture(线段树 || 普通hash标记)

    http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Mem ...

  9. 【HDU 1828】 Picture (矩阵周长并,线段树,扫描法)

    [题目] Picture Problem Description A number of rectangular posters, photographs and other pictures of ...

随机推荐

  1. Hadoop MapReduce编程 API入门系列之join(二十六)(未完)

    不多说,直接上代码. 天气记录数据库 Station ID Timestamp Temperature 气象站数据库 Station ID Station Name 气象站和天气记录合并之后的示意图如 ...

  2. ES6变量的解构赋值

    变量的解构赋值 1.数组的解构赋值 2.对象的解构赋值 3.字符串的解构赋值 4.数值和布尔值的解构赋值 5.函数参数的解构赋值 6.圆括号问题 7.用途 1.数组的解构赋值 ES6 允许写成下面这样 ...

  3. let,const,var三者之间的区别

    在ES6中新增了两种定义变量的命令let和const,在这之前相信大家都对var定义变量很熟悉,那么在了解ES6方法前, 1.我们先来回顾一下var定义变量的方法. 下面来看这段代码: for (va ...

  4. PowerDesigner 逆向工程 Could not Initialize JavaVM!

    原项目的大量的表,使用PowerDesigner 进行逆向工程.提示Could not Initialize JavaVM! 网上找到原因,PowerDesigner 不可以使用64位JDK环境! 有 ...

  5. C++调用Matlab 注意事项

    前言:脑残的使用了C++调用Matlab,没想到Matlab的使用者的智商还真TMD不一般, 竟然有这样的 plot(x_Abnorm_index,Vec2(Abnorm_index),'sb','l ...

  6. Java入门第一季——从此投身Java??

    找工作告一段落. 最后的工作呢,和java紧密相关,也是阴差阳错,不过都是软件开发,都好了,不过以后侧重点肯定是在java这边,php有机会还是一直学下去的,那么美的说~ Java开发第一季  一.简 ...

  7. load 调用的顺序

    主要是依赖关系. 调用的顺序 你过去可能会听说过,对于 load 方法的调用顺序有两条规则: 父类先于子类调用 类先于分类调用 这种现象是非常符合我们的直觉的,我们来分析一下这种现象出现的原因. 第一 ...

  8. 应用二:Vue之ElementUI Form表单校验

    (注:本文适用于有一定Vue基础或开发经验的读者,文章就知识点的讲解不一定全面,但却是开发过程中很实用的)   表单校验是前端开发过程中最常用到的功能之一,根据个人的工作经验总结在此对表单校验功能的基 ...

  9. iOS 小知识

    iOS 各版本: http://www.pig66.com/2018/145_1021/17357553.html

  10. js通过String取得对应全局Object的值

    //假设有个全局对象Person var Person = { 'name' : 'alice' } //通过某种配置,获得了字符串形式的对象名 var thisPerson = 'Person'; ...