[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 ...
随机推荐
- Spring《七》ApplicationContext
1.国际化支持 getMessage()提供了国际化支持. Bean中必须定义为messageSource. <bean id="messageSource" class=& ...
- Hadoop MapReduce编程 API入门系列之最短路径(十五)
不多说,直接上代码. ======================================= Iteration: 1= Input path: out/shortestpath/input. ...
- JS form 表单收集 数据 formSerialize
做后台系统的时候通常会用到form表单来做数据采集:每次一个字段一个字段的去收集就会很麻烦,网站也有form.js插件可以进行表单收集,并封装成一个对象,通过ajax方法传到后台:现在介绍一种直觉采集 ...
- Hashlib 用户名密码加密 2.0
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2018/7/10 0008 11:44# @Author : Anthony.Waa# @ ...
- 微信小程序video组件出现无法播放或卡顿
微信小程序使用video组件播放视频的时候,会出现卡顿或者无法播放的问题,加一个custom-cache=”true“即可解决,这个属性文档上没有,是从小程序开发社区中get到的.
- 错误:the apk for your currently selected variant(app-release-unsigned.apk)is not signed.Please specity a signing configuration for this variant(release)
1:导入android studio project 时总会出现运行处一个红色叉号,这里可以点击选择叉号上面显示的Edit Configurations 查看右下角的错误警告信息.: 2:记录错误: ...
- 计算机二级考试Access教程
本教程对编程语言各种要点进行详细的讲解介绍,从基础知识到实用技术功能,内容涵盖了从数组,类等基本概念到多态.模板等高级概念.教程本着实用的原则,每一小节都结合了可以笔试.面试的常见程序实例,以便从第一 ...
- Kafka学习笔记(4)----Kafka的Leader Election
1. Zookeeper的基本操作 zookeeper中的节点可以持久化/有序的两个维度分为四种类型: PERSIST:持久化无序(保存在磁盘中) PERSIST_SEQUENTIAL:持久化有序递增 ...
- 几个书本上不常见到的C语言函数
函数名称:getcwd #include <unistd.h> char *getcwd(char *buf, size_t size); 作用:把当前目录的绝对地址保存到 buf 中,b ...
- java中的标识符
程序员自己定义的名称,例如类名,方法名,变量等等 标识符命名的规则 1.只能由字母(a-z,A-Z),数字(0-9),下划线(_)和美元符号($)组成 2.不能以数字开头 3.不能与关键字重名 4.严 ...