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 ...
随机推荐
- HDU1115--Lifting the Stone(求凸多边形的重心)
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- forEach用法介绍
array.forEach(callback[, thisArg]) forEach() 方法让数组的每一项都执行一次给定的函数. callback在数组每一项上执行的函数,接收三个参数: curre ...
- radiobutton以及checkbox背景图片拉伸变形的问题
设置RadioButton的text属性,只需要有这个属性就可以(设置“”内容就行),然后再添加textsize属性,将字体大小属性值设置为比较小,我设置为2sp.运行后我们会发现图片变形问题不复存在 ...
- ZOJ 2158 POJ 1789 Truck History
最小生成树,主要是题目比较难懂. #include <cstdio> #include <cstring> #include <cmath> #include &l ...
- ASP.NET MVC 使用带有短横线的html Attributes
我们常常需要一个文本框来输入用户名,在asp.net mvc 中可以使用 TextBoxFor.有时候我们想为这个文本框添加一些特性,比如 html5 的data-,如果直接写data-是会提示错误的 ...
- Javascript和HTML dom
今天在看DOM那一章的时候突然想到一个问题,众所周知的js的数据类型有两种:原始类型和对象类型.其中原始类型又包括以下几种类型:数字型.字符串型.布尔值.null和undefined.其中对象类型包括 ...
- eclipse新建workspace使用之前workspace的个性配置
为使新建的workspace(称作A)的配置,比如主题等等,和之前的workspace(称作B)的配置一样: . 关闭eclipse . 将A中.metadata/.plugins目录下所有文件.文件 ...
- gnome3
http://askubuntu.com/questions/67753/how-do-i-add-an-application-to-the-dash https://wiki.gnome.org/ ...
- Python 线程,进程
Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元 线程不能实现多并发 只能实现伪并发 每次工作 只能是一个线程完成 由于python解释器 原生是c 原生线程 底层都会有一把 ...
- java 区分error和exception
1) java.lang.Error: Throwable的子类,用于标记严重错误.合理的应用程序不应该去try/catch这种错误.绝大多数的错误都是非正常的,就根本不该出现的.java.lang. ...