2016 年沈阳网络赛---QSC and Master(区间DP)
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5900
Enter from the north gate of Northeastern University,You are facing the main building of Northeastern University.Ninety-nine percent of the students have not been there,It is said that there is a monster in it.
QSCI am a curious NEU_ACMer,This is the story he told us.
It’s a certain period,QSCI am in a dark night, secretly sneaked into the East Building,hope to see the master.After a serious search,He finally saw the little master in a dark corner. The master said:
“You and I, we're interfacing.please solve my little puzzle!
There are N pairs of numbers,Each pair consists of a key and a value,Now you need to move out some of the pairs to get the score.You can move out two continuous pairs,if and only if their keys are non coprime(their gcd is not one).The final score you get is the sum of all pair’s value which be moved out. May I ask how many points you can get the most?
The answer you give is directly related to your final exam results~The young man~”
QSC is very sad when he told the story,He failed his linear algebra that year because he didn't work out the puzzle.
Could you solve this puzzle?
(Data range:1<=N<=300
1<=Ai.key<=1,000,000,000
0<Ai.value<=1,000,000,000)
Each test case start with one integer N . Next line contains N integers,means Ai.key.Next line contains N integers,means Ai.value.
n 个pair<int , int>,每次可以选相邻两个pair。如果他们的first不互质就可以把它们都删掉,并且获得second之和的分数,问最大得分。#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <string.h>
using namespace std;
long long a[],b[];
long long dp[][];
long long sum[];
long long GCD(long long a,long long b)
{
return (b==)?a:GCD(b,a%b);
}
int main()
{
int T,N;
cin>>T;
while(T--)
{
scanf("%d",&N);
for(int i=;i<=N;i++)
scanf("%lld",&a[i]);
sum[]=;
for(int i=;i<=N;i++)
{
scanf("%lld",&b[i]);
sum[i]=sum[i-]+b[i];
}
memset(dp,,sizeof(dp));
for(int len=;len<N;len++)
{
for(int i=;i+len<=N;i++)
{
if(sum[i+len-]-sum[i]==dp[i+][i+len-])
{
dp[i][i+len]=dp[i+][i+len-];
if(GCD(a[i],a[i+len])>) dp[i][i+len]+=b[i]+b[i+len];
}
for(int k=i;k<i+len;k++)
{
dp[i][i+len]=max(dp[i][i+len],dp[i][k]+dp[k+][i+len]);
}
}
}
printf("%lld\n",dp[][N]);
}
return ;
}
2016 年沈阳网络赛---QSC and Master(区间DP)的更多相关文章
- 2016沈阳网络赛 QSC and Master
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 5900 QSC and Master 区间DP
QSC and Master Problem Description Every school has some legends, Northeastern University is the s ...
- HDU 5901 Count primes (2016 acm 沈阳网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
- hdu 6199 沈阳网络赛---gems gems gems(DP)
题目链接 Problem Description Now there are n gems, each of which has its own value. Alice and Bob play a ...
- 2019ICPC沈阳网络赛-D-Fish eating fruit(树上DP, 换根, 点分治)
链接: https://nanti.jisuanke.com/t/41403 题意: State Z is a underwater kingdom of the Atlantic Ocean. Th ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- hdu_5900_QSC and Master(区间DP)
题目链接:hdu_5900_QSC and Master 题意: 有n个数,每个数有个key值,有个val,如果相邻的两个数的key的gcd大于1那么就可以得到这两个数的val的和,现在问怎么取使得到 ...
- 2016沈阳网络赛 odd-even number
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- 知方可补不足~用SqlProfiler来监视数据库死锁
回到目录 关于锁的相关知识,大家可以看我的这篇文章<知方可补不足~Sqlserver中的几把锁和.net中的事务级别> 死锁我想大家都知道,当一个对话(线程)占用一个资源时,别一个线程也同 ...
- salesforce 零基础学习(二十)简单APP制作
本篇参考链接:https://developer.salesforce.com/trailhead/project/salesforce_developer_workshop 本篇讲述的是最简单的AP ...
- 多线程 ThreadPool线程池
简单说明一下: 线程池可以看做容纳线程的容器:一个应用程序最多只能有一个线程池:ThreadPool静态类通过QueueUserWorkItem()方法将工作函数排入线程池: 每排入一个工作函数,就相 ...
- ssh(sturts2_spring_hibernate) 框架搭建之struts2
一.struts2完整流程的逻辑(整体的概述) 首先,用户在地址栏中输入你的项目访问路径,然后这个请求会发送到服务器,之后服务器发现在web.xml中配置了一个filter过滤器,并且这个过滤器需要对 ...
- StringUtils 的用法
1.public static boolean isEmpty(String str) 判断某字符串是否为empty,标准是 null == str 或 str.length() == 0 2.pub ...
- sql server 链接到本地实例出错
我在使用VS2010测试package的时候,突然发现sql server 链接到本地实例出错,出错信息如下: “ A network-related or instance-specific err ...
- png图片制作任意颜色的小图标
本内容只要是对张鑫旭PNG格式小图标的CSS任意颜色赋色技术的这篇文章进行详细说明. HTML: <i class="icon"><i class="i ...
- JSP网站开发基础总结《六》
对于本篇需要总结的内容,量估计有点大,大家好好看哈,绝对全是干货,代码的已经运行测试,不存在问题,大家可以参考学习,下面开始本篇的内容. 1.添加数据到数据库: 如何用户在JSP页面的填写的信息输入到 ...
- 那些年,在AngularJS的路上遇到的坑
使用AngularJS这么久以来,遇到过一些坑,之前一直没有以书面的形式整理下,现在好好总结下,以供后面查备. 一.angular scope 在ng-if与ng-show下的区别(两者作用域的差别) ...
- office 2010 安装教程
Microsoft Office 2010,是微软推出的新一代办公软件,提供了一些更丰富和强大的新功能,开发代号为Office 14,实际是第12个发行版.该软件共有6个版本,分别是初级版.家庭及学生 ...