2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 859 Accepted Submission(s): 325
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.
pair<int , int>
,每次可以选相邻两个pair
。如果他们的first
不互质就可以把它们都删掉,并且获得second
之和的分数,问最大得分/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
int t;
int n;
ll key[];
ll value[];
ll dp[][];
ll sum[];
ll gcd(ll a,ll b)
{
if(b==)
return a;
else
return gcd(b,a%b);
}
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=; i<=t; i++)
{
memset(dp,,sizeof(dp));
scanf("%d",&n);
for(int j=; j<=n; j++)
scanf("%d",&key[j]);
sum[]=;
for(int j=; j<=n; j++)
{
scanf("%d",&value[j]);
sum[j]=sum[j-]+value[j];
}
for(int j=n; j>=; j--)
{
for(int d=j+; d<=n; d++)
{
for(int zhong=j; zhong<d; zhong++)
dp[j][d]=max(dp[j][d],dp[j][zhong]+dp[zhong+][d]);
if(gcd(key[j],key[d])>)
{
if(d==j+)
dp[j][d]=value[j]+value[d];
else
{
if(dp[j+][d-]==sum[d-]-sum[j])
dp[j][d]=max(dp[j][d],dp[j+][d-]+value[j]+value[d]);
}
}
}
}
printf("%I64d\n",dp[][n]);
}
}
return ;
}
2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp的更多相关文章
- 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元
hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2016 ACM/ICPC Asia Regional Shenyang Online
I:QSC and Master 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意: 给出n对数keyi,vali表示当前这对数的键值和权值 ...
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
Friends and Enemies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
随机推荐
- OL/SQL编程练习
create or replace procedure pr_first is --一个变量 v_a ) := '总有一天我的生命将走到尽头'; --一个常量 c_b constant ) := '而 ...
- 互斥锁pthread_mutex_t的使用(转载)
1. 互斥锁创建 有两种方法创建互斥锁,静态方式和动态方式.POSIX定义了一个宏PTHREAD_MUTEX_INITIALIZER来静态初始化互斥锁,方法如下: pthread_mut ...
- hdu 4611 Balls Rearrangement
http://acm.hdu.edu.cn/showproblem.php?pid=4611 从A中向B中移动和从B中向A中移动的效果是一样的,我们假设从B中向A中移动 而且A>B 我们先求出所 ...
- IPTables系列:如何配置Ubuntu 14.04中的IPTables防火墙
IPTables基本命令 在向大家介绍复杂防火墙规则之前,还是先上一些简单的料,让大家对IPTables最为基本的命令有一些简单了解. 首先要说明的是IPTables命令必需以root权限运行,这意味 ...
- 佳佳的魔法药水 (vijos 1285)
题目大意: 给出N种药水的价格,然后给出一些形如A B C 的关系,表示 A药水+B药水 可以组合出 C药水(保证 A+B 不会得到多种药水). 要求得到1号药水的最少花费和相应的方案数. N< ...
- html,body最顶层元素.
1,元素百比分是相对父元素,所有元素默认父元素是body. absolute,fixed[只有一个父元素,浏览器窗口]除外[浏览器窗口,为父元素].css3:vh,vw也永远相对,浏览器窗口.heig ...
- 在oracle中创建空间索引
Oracle spatial可以方便的存储空间数据,大量的空间数据必需要使用空间索引去查询.在oracle中创建空间索引必需先建立元数据,否则无法创建索引.创建元数据的代码: insert into ...
- Centos6升级内核2.6到3.x过程
最近公司有一个应用,安装需要内核版本3.1以后,不得已,需要升级下内核版本: 1. 安装必要依赖 # yum groupinstall "Development Tools" #y ...
- CSS 3D旋转 hover 后设置transform 是相对于正常位置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MySQL语句45道练习题及答案
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...