[题目链接]

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系列之实验环境搭建

    实验环境基本配置 硬件:硬盘单节点50GB,1G内存,单核. 操作系统:CentOS6.4 64bit Hadoop:2.20 64bit(已编译) JDK:jdk1.7 磁盘分区: / 5GB /b ...

  2. 第7章 性能和可靠性模式 Failover Cluster(故障转移群集)

    上下文 您已经决定在设计或修改基础结构层时使用群集以提供高度可用的服务. 问题 您应该如何设计一个高度可用的基础结构层,来防止因单台服务器或它所运行的软件出现故障而导致的服务丢失? 影响因素 在设计高 ...

  3. 12) 十分钟学会android--APP通信传递消息之简单数据传输

    程序间可以互相通信是Android程序中最棒的功能之一.当一个功能已存在于其他app中,且并不是本程序的核心功能时,完全没有必要重新对其进行编写. 本章节会讲述一些通在不同程序之间通过使用Intent ...

  4. RN配置

    Write by lz: 详细参考官方网址: http://reactnative.cn/docs/0.43/getting-started.html#content 若是无法安装 Chocolate ...

  5. 还是UVa340

    #include<stdio.h> #define maxn 1010 int main() { int num,a[maxn],i,j,b[maxn]; ; &&num) ...

  6. sql_1

    order by SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC; SELECT Company, OrderNumber ...

  7. 详解优动漫PAINT中的图层模式

    使用优动漫PAINT绘制漫画或者插画的时候,在其新建画布区域有一个基本颜色模式的选项,分别包括彩色模式.灰度模式和黑白位图模式,那么这三个模式有什么区别呢,我们在绘图的时候应该如何选择呢? 彩色模式: ...

  8. 创建dynamics CRM client-side (一) - Client-side Events

    这个系列是帮助大家了解dynamics CRM (customer engagement CE) 的client-side 开发. Client-side Events 1. Form OnLoad ...

  9. vc++创建Win32 Application窗体过程

    #include<windows.h>#include<stdio.h>LRESULT CALLBACK WinSunProc( HWND hwnd, UINT uMsg, W ...

  10. pywinauto进阶练习

    case1.画图工具简单练习 #_*_coding=utf-8_*_ import time from pprint import pprint import logging from logging ...