[题目链接]

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. Array.of()和Array()区别

    Array.of方法用于将一组值,转换为数组. Array.of(3, 11, 8) // [3,11,8] Array.of(3) // [3] Array.of(3).length // 1 这个 ...

  2. Javassist介绍

    要想将编译时不存在的类在运行时动态创建并加载,通常有两种策略: 1. 动态编译 2. 动态生成二进制字节码(.class) 对于第二种策略,实际上已经有诸多比较成熟的开源项目提供支持,如CGLib.A ...

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

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

  4. spring中log4j的使用---转载

    原文链接:http://www.codeceo.com/article/log4j-usage.html 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供 ...

  5. ES5:深入解析如何js定义类或对象。

    1.原始方式 var oCar = new  Object; oCar.color = "blue"; oCar.showColor = function(){alert(this ...

  6. 给DBA 的mysql脚本格式

  7. 记一次IOS对 JS的支持问题

    最终在这位博主那块找到问题https://blog.csdn.net/github_36487770/article/details/82465741 在利用Vue开发一个功能时遇到时间拼接格式化问题 ...

  8. 动态规划——Buyer

    题目链接 题目描述 哆啦A梦班级举办个party,当然吃的东西必不可少,哆啦A梦负责采购任务,他得到了一份清单,上面注明不同食品的受欢迎程度,哆啦A梦需要用一定的价钱尽可能达到的更大的受欢迎程度!例如 ...

  9. js将timestamp对象与时间字符串之间的转换

    1. 时间戳转日期字符串 var timestamp = timestampObj.time;获取时间戳的毫秒数 var d = new Date(timestamp); //根据时间戳生成的时间对象 ...

  10. python笔记4----字典

    1.哈希: 输入任意长度,输出固定长度. 即判断是否哈希,即判断可不可变. 2.创建字典 (1)直接创建:dic={1:'a',2:'b',3:'c'} (2)dict函数创建: list=[(1,' ...