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 ;
}

最新文章

  1. git 学习使用总结三(远程仓库操作)
  2. Web服务器与Servlet容器
  3. js遍历集合
  4. UVa 11732 (Tire树) &quot;strcmp()&quot; Anyone?
  5. JADE提升篇
  6. 高清摄像头MIPI接口与ARM处理器的连接
  7. Pet--hdu4707
  8. EF 6.0使用小计
  9. Swift - 本地数据的保存与加载(使用NSCoder将对象保存到.plist文件)
  10. effective c++ 条款11 Handle assignment to self in operator=
  11. CodeForces 755C PolandBall and Forest (并查集)
  12. bzoj 3999: [TJOI2015]旅游
  13. 计算机网络关于IP地址的计算问题
  14. Object-Oriented(二)原型对象
  15. (4.29)sql server中有关于GO的坑
  16. Vue 动态绑定类名
  17. Microsoft实现的IOC DI之 Unity 、Service Locator、MEF
  18. Python实现鸢尾花数据集分类问题——基于skearn的LogisticRegression
  19. CentOS 7.X下 -- 配置nginx正向代理支持https
  20. 牛客网——G送分了(py)

热门文章

  1. spring 控制事务
  2. http://debugjs.com/
  3. AMD正式公布第七代桌面级APU AM4新接口
  4. css设置input中placeholder字体
  5. 贴一下WC总结里提到的那道裸题吧。。。
  6. HDU——PKU题目分类
  7. python入门教程链接
  8. Ubuntu编译源码程序依赖查找方法
  9. python之路一
  10. NOSQL概要