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 ...
随机推荐
- strstr strchr strrchr
通过函数的定义来区分: 1.strstr: 返回子串出现的第一次位置 char *strstr(const char *haystack, const char *needle) 可见,strstr函 ...
- VS2010连接SQLite数据库
Visual studio 2010及以上版本,连接SQLite数据库 1.在Sqlite开发站点下载SQLite的.exe安装包 Ctrl+F搜索这条语句:This is the only setu ...
- for循环语句示例应用
age = 22 #优化前 ''' for i in range(10): guess_num = int(input('input your guess num:')) if guess_num = ...
- mac下安装apache+php+mysql
运行“sudo apachectl start”,再输入帐号密码,这样Apache就运行了. 运行“sudo apachectl -v”,你会看到Mac OS X 10.6.3中的Apache版本号: ...
- form v
<form name="example_form" action="http://google.com" method="POST"& ...
- Mongoose 是什么?
Mongoose 参考手册 标签(空格分隔): MongoDB 一般我们不直接用MongoDB的函数来操作MongoDB数据库 Mongose就是一套操作MongoDB数据库的接口. Schema 一 ...
- CoHTMLDocument
http://blog.csdn.net/dlwxn/article/details/2860329 http://www.itnose.net/detail/120267.html 不知道是 线程内 ...
- 戴文的Linux内核专题:07内核配置(3)
转自Linux中国 OK,我们还继续配置内核.还有更多功能等待着去配置. 下一个问题(Enable ELF core dumps (ELF_CORE))询问的是内核是否可以生成内核转储文件.这会使内核 ...
- Javascript计数器
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content=&q ...
- JS 验证一组input框是否为空的方法
function checkInput() { var $tr = $("#tb_confirmed .scrollContent").find("tr"); ...