jzoj5864
本來這道題該100的,沒想到考試沒想最短路,直接跑暴力了
實際上這道題有原題跳樓機
那道題在模x的意義下統計答案
現在,我們要統計n個數的答案
30pts為提高組原題
剩下70pts,可以記dis[i]表示在模a[1]意義下為i,由a[2]~a[n]可以組合而成的最小數
則i介於0~a[1]-1 ,由於a[1]很小,不會爆炸
每一次從i~(i+a[j])%a[1]連邊權為a[j]的邊,代表我們需要a[j]的代價將模a[1]意義下為i的最小值轉變為(i+a[j])%a[1]
跑完最短路之後,我們就對dis[0~a[1]-1]取max,max為在模i意義下最小不能表示出來的數+i
所以答案為max-i
代碼:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,h[1000010],nxt[1000020],v[1000020],w[1000020],ec,vis[1000020],d[1000010],x[10];
void add(ll a,ll b,ll c){v[++ec]=b;w[ec]=c;nxt[ec]=h[a];h[a]=ec;}
struct no{
ll d,x;
bool operator <(const no &rhs)const{
return d>rhs.d;
}
};
void dij(ll s){
priority_queueq;
q.push((no){0,s});
for(ll i=0;i<=1000000;i++)d[i]=LONG_LONG_MAX/3;
d[s]=0;
while(!q.empty()){
no x=q.top();q.pop();
if(vis[x.x])continue;
vis[x.x]=true;
for(int i=h[x.x];i;i=nxt[i])
if(d[v[i]]>d[x.x]+w[i]){
d[v[i]]=d[x.x]+w[i];
q.push((no){d[v[i]],v[i]});
}
}
}
int main(){
freopen(“sequence.in”,“r”,stdin);
freopen(“sequence.out”,“w”,stdout);
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
scanf("%lld",&x[i]);
if(n==2){
printf("%lld",x[1]*x[2]-x[1]-x[2]);
return 0;
}
ll ans=0;
for(ll i=0;i<x[1];i++)
for(ll j=2;j<=n;j++)
add(i,(i+x[j])%x[1],x[j]);
dij(0);
for(ll i=0;i<x[1];i++)
ans=max(ans,d[i]);
printf("%lld\n",ans-x[1]);
}
jzoj5864的更多相关文章
随机推荐
- Castle ActiveRecord学习(三)数据映射及特性描述
Model中的Demo: using Castle.ActiveRecord; using Castle.ActiveRecord.Queries; using System; using Syste ...
- POJ 1122.FDNY to the Rescue! Dijkstra
FDNY to the Rescue! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2808 Accepted: 86 ...
- 【附案例】UI交互设计不会做?设计大神带你开启动效灵感之路
随着网络技术的创新发展,如今UI交互设计应用越来越广泛,显然已经成为设计的主流及流行的必然趋势.UI界面交互设计中的动效包括移动,滑块,悬停效果,GIF动画等.UI界面交互设计为何越来越受到青睐?它有 ...
- html5移动开发。
禁止滚动 $('#idl').bind("touchmove",function(e){ e.preventDefault(); }); 图片居中 (因为图片比较特别,所以需要在外 ...
- tensorflow的transpose
从图中看出来perm=[1,0,2] 表示第一个维度和第二个维度进行交换. 默认的是[0,1,2] 所以perm=[1,0,2] 表示第一个维度和第二个维度进行交换.0,1,2表示index.
- 关于IBatisNet的配置文件中数据库连接字符串加密处理
我们通常在IBatisNet配置文件 properties.config 加入数据库连接字符串.数据库连接字符串直接放在里面,没有被加密,很不安全.如果我们把 properties.config 文件 ...
- Kendo UI中TreeView 放入tabstrip中,大数据量时超过边框的解决方案。
参考http://www.kendoui.com/forums/ui/tabstrip/tabstip-with-treeview-treeview-breaking-out-of-tabstrip. ...
- ipad The data couldn’t be read because it isn’t in the correct format
原来是land left和land right都勾选的,去掉land left后出现这个问题
- 2018.07.08 hdu6183 Color it(线段树)
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Proble ...
- day08(File类 ,字节流)
File类 构造方法 File(String path); FIle(String parent, String child); File(File parent, String child) ...