codevs 2851 菜菜买气球
2024-08-31 05:44:57
dp加二分法
链接:http://codevs.cn/problem/2851/
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std; int a[];
int b[];
int n,m,k;
int f[][]; int dp(int x,int y)
{
if(x==y) return a[x];
if(f[x][y]>) return f[x][y];
int mid=(x+y)/;
return f[x][y]=dp(x,mid)+dp(mid+,y);
} bool IsP(int x)
{
if(x<=) return false;
for(int i=;i<=floor(sqrt(x));i++)
if(x%i==) return false;
return true;
} int main()
{
cin>>n;
for (int i=;i<=n;i++)
cin>>a[i];
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
f[i][j]=-;
int ans=;
int l,r; for (int i=;i<=n;i++)
for (int j=i;j<=n;j++)
{
int p=dp(i,j);
if (IsP(p)&&p>ans)
{
l=i;
r=j;
ans=p;
}
}
cout<<l<<" "<<r<<" "<<ans;
return ;
}
最新文章
- git 学习使用总结三(远程仓库操作)
- Web服务器与Servlet容器
- js遍历集合
- UVa 11732 (Tire树) ";strcmp()"; Anyone?
- JADE提升篇
- 高清摄像头MIPI接口与ARM处理器的连接
- Pet--hdu4707
- EF 6.0使用小计
- Swift - 本地数据的保存与加载(使用NSCoder将对象保存到.plist文件)
- effective c++ 条款11 Handle assignment to self in operator=
- CodeForces 755C PolandBall and Forest (并查集)
- bzoj 3999: [TJOI2015]旅游
- 计算机网络关于IP地址的计算问题
- Object-Oriented(二)原型对象
- (4.29)sql server中有关于GO的坑
- Vue 动态绑定类名
- Microsoft实现的IOC DI之 Unity 、Service Locator、MEF
- Python实现鸢尾花数据集分类问题——基于skearn的LogisticRegression
- CentOS 7.X下 -- 配置nginx正向代理支持https
- 牛客网——G送分了(py)