/************************************************************** Problem: 2118 User: y20070316 Language: C++ Result: Accepted Time:1860 ms Memory:8616 kb ****************************************************************/ #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; typedef long long LL; const int N=13; const int M=500001; const LL MAX=10000000000000; int n; LL BMin,BMax; int p[N],vtx; LL dis[M]; int q[M],h,t,v[M]; inline LL query(LL w) { LL cnt=0; for (int i=0;i<vtx;i++) if (dis[i]<=w) cnt+=(w-dis[i])/vtx+1; return cnt; } int main(void) { scanf("%d%lld%lld",&n,&BMin,&BMax); for (int i=1;i<=n;i++) scanf("%d",&p[i]); vtx=p[1]; for (int i=2;i<=n;i++) if (vtx>p[i]) vtx=p[i]; int now,nxt; for (int i=1;i<vtx;i++) dis[i]=MAX; v[q[t=1]=0]=1; for (;h^t;) { v[now=q[h=h%vtx+1]]=0; for (int r=1;r<=n;r++) { nxt=(dis[now]+p[r])%vtx; if (dis[now]+p[r]<dis[nxt]) { dis[nxt]=dis[now]+p[r]; if (!v[nxt]) { v[nxt]=1; q[t=t%vtx+1]=nxt; } } } } printf("%lld\n",query(BMax)-query(BMin-1)); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u013598409/article/details/47037099