2016沈阳网络赛 QSC and Master
QSC and Master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
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.
3
1 2 3
1 1 1
3
1 2 4
1 1 1
4
1 3 4 3
1 1 1 1
2
0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
ll dp[maxn][maxn],a[maxn],b[maxn],sum[maxn];
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(dp,,sizeof dp);
rep(i,,n)scanf("%lld",&a[i]);
rep(i,,n)scanf("%lld",&b[i]),sum[i]=sum[i-]+b[i];
rep(i,,n)
{
for(j=;j+i-<=n;j++)
{
if(gcd(a[j],a[j+i-])!=&&dp[j+][i-]==sum[j+i-]-sum[j])dp[j][i]=b[j]+b[j+i-]+dp[j+][i-];
for(k=j+;k<=j+i-;k++)dp[j][i]=max(dp[j][i],dp[j][k-j]+dp[k][j+i-k]);
}
}
printf("%lld\n",dp[][n]);
}
//system("Pause");
return ;
}
2016沈阳网络赛 QSC and Master的更多相关文章
- 2016 年沈阳网络赛---QSC and Master(区间DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...
- 2016沈阳网络赛 odd-even number
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- HDU 5901 Count primes (2016 acm 沈阳网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
- 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...
- 沈阳网络赛D-Made In Heaven【k短路】【模板】
One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci ...
- 沈阳网络赛G-Spare Tire【容斥】
17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an} can be expressed as: \display ...
随机推荐
- 感知哈希算法的java实现
一.原理讲解 实现这种功能的关键技术叫做"感知哈希算法"(Perceptual Hash Algorithm), 意思是为图片生成一个指纹(字符串格式), 两张图片的指纹 ...
- HOSTS文件修改后不起作用的原因
如果是通过记事本修改,其实是没有问题的,如果有问题,网上搜到的是ipconfig /flushdns之类的 如果是批量程序写的,那就要小心了, 一定要ANSI(美标格式的,忘了英文是什么来着) 保存后 ...
- MySQL 不允许从远程访问的解决方法
解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 ...
- vb asp.net的一些属性值
AutoGenerateColumns 就是自动产生列的意思gridview等控件,如果设置了AutoGenerateColumns=true,就能够根据数据源的实际情况,自动生成gridview表格 ...
- OpenCV成长之路:图像直方图
http://ronny.blog.51cto.com/8801997/1394115 2014-04-11 13:47:27 标签:opencv 直方图 统计表 原创作品,允许转载,转载时请务必以超 ...
- JavaScript高级程序设计:第十四章
第十四章 一.表单的基础知识 在HTML中,表单是由<form>元素来表示的,而在javascript中,表单对应的则是HTMLFormElement类型.HTMLFormElement继 ...
- Linux 配置VNC远程桌面
X11 提供的 display manager 为 xdm ,而著名的 KDE 与 GNOME 也都有自己的 display manager 管理程序,分别是 kdm 与 gdm .你可以透过三者中任 ...
- 获取sql执行时间
sql server中获取要执行的sql或sql块的执行时间,方法之一如下: declare @begin datetime,@end datetime set @begin =getdate() - ...
- Simple But Useful Samples About 'grep' Command(简单实用的grep 命令)
Do the following: grep -rnw '/path/to/somewhere/' -e "pattern" -r or -R is recursive, -n i ...
- WPF InkCanvas 画图 基础使用教程
大家好,由于很多原因,我有很长一段时间没有在 CSDN 上分享我的学习成果了,如今终于可以回归分享之路了. 之前在做一个项目的时候,想在一个区域里绘制自己的图形,于是上网搜索资料,无意中找到了 Ink ...