目录:

K Airdrop

I Soldier Game

L Sub-cycle Graph

G Repair the Artwork

————————————————————

ps:楼主脑残有点严重,很容易写错别字和语言组织混乱,如果在读文章时遇到,可以在评论区里回复一下,我好改(花式骗评论)

补题地址:http://acm.zju.edu.cn/onlinejudge/showProblems.do?contestId=1&pageNumber=31

顺便好人做到底,给大家凑个11/13的题解出来。(据说A题题解某个大佬是有写的,但是我找不到,有没有好心人告诉我一下)

B:https://www.cnblogs.com/xseventh/p/9986194.html(摸鱼的队员终于把B题补掉了,dsu on tree)

C:https://blog.csdn.net/lzyws739307453/article/details/83932183 (分类讨论)

D:https://blog.csdn.net/LSD20164388/article/details/83893264(枚举+讨巧)

E:https://blog.csdn.net/Code92007/article/details/83932020(二分+贪心)

F:http://www.cnblogs.com/qq965921539/p/9905086.html (构造题)

J :https://blog.csdn.net/Code92007/article/details/83930044(贪心)

M:傻逼签到题,递归到1时判奇偶就行了

____________________________

K Airdrop

虽然K题现场过的比较少,但实际上是一个排个序 ,按顺序枚举x0,大力数数的垃圾题,只是现场榜歪没人看而已。emmmm,根据重现的结果,可能k确实有一点难度,这里给一下提示,首先这个人啊,是优先先动y,再动x的,所以不和x=x0在同一条线上的点,只要与(x0,y0)的曼哈顿距离相同就有可能会撞。因此我们要在(x0,y0)的左右两边分别数每种曼哈顿距离出现的次数。显然左右的是可以拆开数,所以我们先把所有x0左侧曼哈顿距离相同的点的数量数完,在数右边,最后在数一下多少个点的x=x0就行,如果你有注意到题目有说所有点的初始位置是不一样的,可能会好写很多。

  现在以数左边曼哈顿距离相同的点的数量为例,首先要注意到什么情况下曼哈顿距离相同点并不会抵消掉而是会留下一个,这里举个栗子,当有三个点对于(x0,y0)的曼哈顿距离相同时,万一有两个因为比较早相遇而挂掉,则最后一个人就能活到空投那里。解决办法也简单,注意到,他们只能在y=y0这条直线上相遇,早相遇的点,他们相遇的x也比较小,只要在从左往右枚举x0的过程中,顺便把在上个x0的相撞死的人对于的数量贡献去掉就好了。再维护一下当前有多少个曼哈顿距离只出现了1次,只出现一次的点都是能活着到空投的。

最后的最后,在教一下怎么数量,因为对于不同的x0,y0所有点的曼哈顿距离都在变的,我们不能每次重新数所有距离出现的次数。但是对于在(x0,y0)左侧点,如果他们对于(x0,y0)曼哈顿距离相同,随着(x0,y0)右移他们还是会相同的,所以干脆直接数他们到(xm,y0)的曼哈顿距离就行了,xm为x0坐标的最大值。 他们到(xm,y0)距离相同的话,则这些点到任意他们的右侧(x0,y0)距离也肯定相同。

 #include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int const maxn=2e5+;
int x[];
int y[];
vector<int>e[maxn],q,que,res;
int sum[];
int num[];
void clear(int n,int x0,int y0)
{
for(int i=;i<=n;i++)
{
num[abs(x0-x[i])+abs(y0-y[i])]=;
}
}
int main()
{
int i,j,n,m,w,t,y0,xm=1e5+,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&y0);
q.clear();
q.push_back();
// e[0].clear();
for(i=;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
e[x[i]].clear();
e[x[i]+].clear();
// e[x[i]-1].clear();
q.push_back(x[i]);
q.push_back(x[i]+);
// q.push_back(x[i]-1);
}
sort(q.begin(),q.end());
q.erase(unique(q.begin(),q.end()),q.end());
for(i=;i<=n;i++)
{
e[x[i]].push_back(y[i]);
}
int ans=,temp=;
clear(n,xm,y0);
for(int xx:q)
{
sum[xx]=e[xx].size();
if(temp)
{
que.clear();
for(int yy:e[temp])
{
k=abs(yy-y0)+abs(xm-temp);
num[k]++;
if(num[k]==)
{
ans++;
}
else
{
que.push_back(k);
}
}
for(int pos:que)
{
if(num[pos])
ans--;
num[pos]=;
}
}
temp=xx;
sum[xx]+=ans;
// printf("(%d %d)\n",xx,sum[xx]);
}
reverse(q.begin(),q.end()); ans=,temp=;
clear(n,,y0);
res.clear();
for(int xx:q)
{
if(temp)
{
que.clear();
for(int yy:e[temp])
{
k=abs(yy-y0)+abs(-temp);
num[k]++;
if(num[k]==)
{
ans++;
}
else
{ que.push_back(k);
}
}
for(int pos:que)
{
if(num[pos])
ans--;
num[pos]=;
}
}
temp=xx;
sum[xx]+=ans;
res.push_back(sum[xx]);
//printf("(%d %d %d)\n",xx,sum[xx],ans);
}
sort(res.begin(),res.end());
printf("%d %d\n",res.front(),res.back());
}
return ;
}

K

I Soldier Game

  这题两种写法,一种是枚举最小值+线段树单点更新维护可行最大值。 另一种是dp (神仙知道怎么写,我不知道)。这题思路还是比较复杂了,然后HDU的CSY巨巨现场一眼标算,果然神仙和凡人是不能比的。

当我问群巨怎么做时,他们只给我“枚举最小值+线段树维护可行最大值“,这几个关键字,我百思不得其解,终于想了几天后顿悟了。o(╥﹏╥)o

  首先。我们考虑一个动态规划问题:给出a个长度为1的区间和b个长度为2区间,每个区间都有权重。从中取出若干个不相交的区间,在满足覆盖满[1,n]情况下,使得【权重最大的区间】的权重最小,要怎么做。

一个显然的想法:令dp[i]代表覆盖满[1,i]的所有方案中,权重的最大值最小为多少。然后按左端点从小到大枚举区间,进行状态转移就行了,复杂度O(a+b)。

  然后现在我就可以得到I题的一个O(n^2)写法了,具体做法是这样的:

  我们把n个长度为1的区间和n-1长度为2的区间按权值排序 ->枚举最小值 -> 将权值小于最小值的区间删去  ->

-> 然后对剩下的区间做dp,求出可行的【最小的最大值】,计算最大值和当前枚举的最小值之差,并更新答案。

  上面那个做法虽然不够优越,但是已经为正确的做法已经铺好了路,因为上面涉及到一个线性dp的单点修改后在查询,套个老掉牙线段树维护dp值不就可以在log(n)的时间内查询到修改后的值了吗。

所以现在我们就有了个nlog(n)做法,核心在于怎么把dp挂到线段树上。不过说起来容易做起来难, 因为你发现如果你要搬到线段树上要维护一坨东西才行,

不过核心思想并不复杂,只是枚举一下树上孩子合并时是否有区间跨过两个孩子就行了,合并操作的具体代码长这样

 struct Node
{
///m代表中间,l代表左,r代表右
int rl;
int m;///只包含中间,不包含区间的左右端点
int mr;///包含中右
int lm;///包含左中
int lmr;///包含左中右
int set(int i)
{
rl=a[i][];
lm=mr=-INF;
lmr=a[i][];
m=INF;
}
inline Node operator+(const Node &b)const
{
Node ans;
ans.m=min(max(mr,b.lm),max(max(m,rl),b.m));
ans.lm=min(max(lmr,b.lm),max(max(lm,rl),b.m));
ans.mr=min(max(mr,b.lmr),max(max(m,rl),b.mr));
ans.lmr=min(max(lmr,b.lmr),max(max(lm,rl),b.mr));
ans.rl=b.rl;
return ans;
} };

有没有被吓到,不过努力思考一下应该还是看得懂的。

完整的AC代码如下(我删掉一个区间的方法,是把这个区间权值赋值成无穷大,这样对答案就没有贡献了,话说我居然是跑得最快的╰(*°▽°*)╯):

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
#define N 280000
int a[][];
const int INF=(<<)-;
struct Node
{
///m代表中间,l代表左,r代表右
int rl;
int m;///只包含中间,不包含区间的左右端点
int mr;///包含中右
int lm;///包含左中
int lmr;///包含左中右
int set(int i)
{
rl=a[i][];
lm=mr=-INF;
lmr=a[i][];
m=INF;
}
inline Node operator+(const Node &b)const
{
Node ans;
ans.m=min(max(mr,b.lm),max(max(m,rl),b.m));
ans.lm=min(max(lmr,b.lm),max(max(lm,rl),b.m));
ans.mr=min(max(mr,b.lmr),max(max(m,rl),b.mr));
ans.lmr=min(max(lmr,b.lmr),max(max(lm,rl),b.mr));
ans.rl=b.rl;
return ans;
} };
const int MAXN=;
struct Segment_tree
{
int size;
Node node[MAXN];
void update(int pos)
{
node[pos]=node[pos+pos]+node[pos+pos+];
}
void build(int n)///申请空间
{
size=;
while(size<n)///计算几个刚好能套住整个区间的区间容量
size<<=;///size=size*2
// printf("size=%d\n",size);
}
void build(int n,int flag)///申请空间,并建树
{
build(n);
int i;
for(i=n; i<size; i++)
{
a[i][]=-INF;
a[i][]=INF;
}
for(i=; i<size; i++)
{
node[size+i].set(i);
}
for(i=size-; i>; i--)
{
update(i);///数值从低到高更新上去
}
}
void change(int x)
{
x+=size;
node[x].set(x-size);
while(x>)
{
// printf("[%d]\n",x);
x>>=;
update(x);
}
}
void put()
{
int i=,j=,s=size*,k,len=;
for(i=; i<=*size-; i++)
{
if(i==j)
{
puts("");
j<<=;
s>>=;
for(k=; k<len*(s/-); k++)
printf(" ");
}
printf("%3d",node[i].lmr);
for(k=; k<len*(s-); k++)
printf(" ");
}
puts("");
} } tree;
typedef pair<int,int> PI;
PI b[];
int cmp(const PI &x,const PI &y)
{
return a[x.first][x.second]<a[y.first][y.second];
}
int main()
{
int n,m,t,i;
//freopen("1.in","r",stdin);
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int top=;
for(i=; i<n; i++)
{
scanf("%d",&a[i][]);
b[top++]=make_pair(i,);
if(i>)
{
a[i-][]=a[i-][]+a[i][];
b[top++]=make_pair(i-,);
}
}
a[n-][]=INF;
sort(b,b+top,cmp);
tree.build(n,);
int j=;
int mn;
long long ans=INF*2LL;
for(i=; i<top;)
{
mn=a[b[i].first][b[i].second];
// printf("i=%d\n",i); if(tree.node[].lmr==INF)
{
break;
}
ans=min(ans,tree.node[].lmr-(long long)mn);
while(j<top&&a[b[j].first][b[j].second]<=mn)
{
a[b[j].first][b[j].second]=INF;
tree.change(b[j].first);
j++;
}
i=j;
} printf("%lld\n",ans);
}
return ;
}

I

L Sub-cycle Graph

  好吧,这是一个比较傻吊的组合数学题,但是现场的时候看错条件了,越想越复杂_(¦3」∠)_。

题意是问有多少种n个点m条边的图,是一个连通简单环图的子图。

首先因为是连通简单环图,所以母图必须只有一个简单环且连通所有结点,在断掉一些边后,必然会变成n-m条链的组合。

现在我们先来考虑一个比较简单的问题:n个结点组成一条链有多少种本质不同的方案

显然这个数列的前n项是1,1,3,12,……,n!/2。

写成Σai/(i!) x^i 的指数型生成函数的话(什么你不会指数型生成函数,那还不赶紧去学),就是

aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4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SqkimmjsbJ3XIiwdmawJ9Fm+geZouBEOL2EPKhr9jwxVU/u9DrL9bYIV2XTcvTOkBuw4FKFYWQDy5VX7NDNEEjNETIjETImjDKiEYmYqV7RedEzLhiCDfVnv5BBUgoSgEsUvl+Ki9u5MABQGUDIZJGROwFWR13Fy0piRdImcAiwSjsc4uMGr9GMBe0AbBb0mYKBZs23tOJz4PssFlf3pGQ2A8yWTkxMqMQE2lF0+QIFPYaJC0BP0jh0Jg+heRMC0260g+ZIRsYxDN8f5cw3iCBMiAgvKthpcPIuag0VTvfVEEIKAqALAz4+YKBZs23tOJz4PssFlf3ph1OHG3IRQwQ8FU1C5Cje0DnqY7dGmMVvU4QQUF5IUSTBFD+nB+E0EFRuXP1qCCpBQlAJYpfL8VBAmwCEAMAGJopmgCYVjESgkr1hLh0WmSw2NwNcC6DGIiGAFQrgD0fSpUqKhKw1DFAygzwaXDyLmoNFU73016ExllfQFjo8XjcqOFDYEqnY5cGkXPPsUPY6wJ9VmegeLouBAeJ2kPCJpkOkwsYxjLvH+cocCAEpiAIXlWwCh+eqlBjlR5BMP3qVKlSpUaU0JJioAcBzjGs0v5CBHZT5BTZ06ubYFLtUMZQLnt+UqKl5ONYGZg3kLd42TkNn+pJArKAvTw+dX90giLDCSjvBdMOruXnCGfCCIlHcdHnzjMzLCxgoziawgZly7FQXRtFJpbAFLq6kogaCZN0quOuSh0Ui8Sqo/J0+Uk/TBwJTpi586uzS1e4M2NuvqCRMCIFgvIV/b8NjfNXEymIGCB1p8IhQEdmIdOC0EG3a0zbVKg/BP8AEBEz0zCUeA7zCJUPFfbrJDxiSjRj0g/UMEI1QHilL+zS8NSaDcawJLgx/Uud2T3ZkWdXTzk4pHKMjc2w6+io+9EyIks5b460AIgV5hEqHivt+FdY6Nmm5dwi2S3aQK7GCvGUOsr2u/8AGTiLBBHA5OXBODf5xu2ikEqWe5CjJowb3z/1b//Z" alt="" />

则组成k条链的指数型生成函数就是

则题目想要的答案就是bn /k!。 为啥除k! ?    因为我们的答案是不考虑这k条链出现的先后顺序的。

 然后开始FFT?,   答案是NO!

上面那个多项式我们并不需要真的做多项式的幂运算。首先上面的式子可以拆成这样。

aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wgARCAA5ATIDASIAAhEBAxEB/8QAGgABAQEBAQEBAAAAAAAAAAAAAAQFAwIBBv/EABYBAQEBAAAAAAAAAAAAAAAAAAABAv/aAAwDAQACEAMQAAAB/fgAitxbS1Phm79lojnZk61hx7KAOB3AAAAOB3BL3hoKQHDuAAcc7Qzyjxz5po055bvMYu5TCiGqKM/9Dm7WpBZHZLj9If0RDP8AfJtJhxpzLBLp4aV/POtLn6WLVZX9jLoZvqU9bCMq9efQB8npDn0DE28k1kwmvzNUce449gAA8ffQAAA59A5ZO3kmsi9kmjBpgAAAAAAAAAAAAAAAAAAAAAAH/8QAKBAAAgIBBAIBAwUBAAAAAAAAAgMBBAAFEhMUEBEgIjA0ISMzNUBg/9oACAEBAAEFAvgi0Fg/LmcKTZsFFgX/AOSw8ayQLeH26n5xFZ3QRQuotQ2XfXYc5ddVIlHOG2AP4GyAZ9lTIcvxf/rq/wCN4hkS74N/RNL6NPRbCwNUysQFdCjwhEx4w3eo3MSp0AhShXPJKFvtaWgNie9UjAMWDGpDJWqx2TeyRIjavUfDLa1WOT9pHJ1Yly7wsNdinVmtFUysRjFraIACxx7JruioXeyJgh8O/gqkY6ZWSxc0Q96f01Z01Z01Z01Z01Z01YFYFmiN+oaT/V512YESIuXZlozMjYjZfcLZ1JiBbK0AqbIvbjxNqTmRCqV2X+uTVpj2NEPen9NWdNWdNWdNWXQ3LwlF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wEBPwEf/8QAFxEAAwEAAAAAAAAAAAAAAAAAAAEgQf/aAAgBAgEBPwEyHH//xAAtEAACAQIDBQYHAAAAAAAAAAABAgMAERIhURAgMpPREyJBYZGxNFJygYLB0v/aAAgBAQAGPwLZDHjHZOrd3DpvQSLCxRAQWuPH77lmEn4xs3tXDPyH6Vwz8h+lcM/IfpQULLfziYfqsWIADUUO1cLc2HnugPmny60frX3okKWOgr4Ob1T+qcCVo8uJfCkmdmMlsLZ5emzDKCRoGIoAXy1N9iMwuUNxTYFtiNzs/8QAIhABAAEDAwUBAQAAAAAAAAAAAREAITEQIFFBYXGBkcHw/9oACAEBAAE/IdLr5IXTDr77bjM9qHDoytsMNqTbPodlWrVKMXH/AFhUs8uZP2mXOzleNuANe2y71/F40ZXccv1ChXDURo+VRLTvEBGHhMmc6DSVn8K0NhBBIvrnTr4wWzSpMS4t2/rT/9oADAMBAAIAAwAAABDxzzTy9Qvf/8QAGxEBAAICAwAAAAAAAAAAAAAAAQARIEEhMfD/2gAIAQMBAT8Qj2+1gIPM3BpuBU//xAAeEQEAAgEEAwAAAAAAAAAAAAABABExICFhgbHB0f/aAAgBAgEBPxCGHfl0CyhqGE59HyJZUW95/8QAHxABAQEAAgIDAQEAAAAAAAAAAREhADFBURAgYYGR/9oACAEBAAE/EPirFqQAaWq74H9fYNnt4SRAIhuX0Py9ZwUjSxFTQhzq3r2fQECBVgbEjBdMOvLvXfHl7WuyBsTvhL4gpRkBV7PGX6qxrpeQj7haHvdhORzRDRj+Y/7CcCCZZWJwxZJsEttRz3NnScQnAlhhvsKjy2YcP18glERZWIJbHri5IjIAzUVfqq/FCSPLCaDHPDThDG3sRUqxVYQqs34//9k=" alt="" />

是一个特殊的多项式,与这个多项式做卷积相当于对系数求前缀和。

乘k次,就相当于求k次前缀和,求k次前缀和的第m项,想必现在是个人都应该会了。

所以到此题目就做完了,算法复杂度O(m)

 #include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
ll fac[],ifac[];
const ll mod=1e9+,inv2=(mod+)/;
ll C(int n,int m)
{
if(m>n)
return ;
return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
int n=1e5+,m,t,i,j,k;
ifac[]=;
ifac[]=;
for(i=; i<=n; i++)
{
ifac[i]=(mod-mod/i)*ifac[mod%i]%mod;
}
fac[]=;
for(i=; i<=n; i++)
{
fac[i]=fac[i-]*i%mod;
ifac[i]=ifac[i-]*ifac[i]%mod;
}
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
if(m>n)
{
puts("");
}
else if(m==n)
{
printf("%lld\n",fac[n-]*inv2%mod);
}
else
{
ll ans=,temp=;
k=n-m;
for(i=;i<=m;i++)
{
// printf("[%d %d],%d\n",k,m-i,C(k+(m-i)-1,m-i));
ans+=C(k,i)*temp%mod*C(k+(m-i)-,m-i)%mod;
ans%=mod;
temp=temp*-inv2%mod;
if(temp<)
temp+=mod;
}
printf("%lld\n",ans%mod*fac[n]%mod*ifac[k]%mod);
} }
return ;
}

L

 

G Repair the Artwork

问题1:

只有0和1情况方案数怎么计算?

在只有0,1的时候,可行方案数显然 【可选的区间数】^m

问题2:

只有2的情况方案数怎么计算:

为了方便表示,我们约定一下记号(不然说起来会像绕口令)

  • 如果一个位置上的2被当做1用(即一定不覆盖这个位置)我们把用×表示这个2,
  • 如果一个位置上的2被当做0用(即这个位置可能被覆盖,也可能没有被覆盖)我们把用O表示这个2。
  • 如果一个位置上的2一定被覆盖用Θ表示,
  • {??……?} 表示每个2满足??……?约束情况下的方案数。

现在我们来推导一下只有两个2时方案数怎么计算

则我们要求的答案{ΘΘ},随便容斥一下就可展开成如下形式:

aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjI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AEGWMo7NppGio7XeWrgLoaKrQKbP41gFow0hz6iNuvLwsRE25OMCXDbKTSeiUOJAWcCaDXVSF9nO4nt1IgVERLSWk7hpiSUOjNhyiJpG4VXzDnCRkWWC2XeOq0cGkgTPUh9LvGFmA9iPAtdqr1dRwspJyO3o2DTtLb82X09A/tJTeE+4aA5Yjme+a6f3vGtRJups9EO9vWtQTU1AWlBZWg07wVb0sER9afdqr7VQrjBJ1VLJvoMX8+EgLOBNBrqpC+zncT26kQKiIlpLSdzphKKDsSf222bCVqQwmmFqc6bDYWc1gt1/YXER9s+kwIMegQAODpdcPY/AOHFiGj0Whn6N1idAOuxxuOo9+yr39uSERkAs1fCyVtNAFNkgpX+RtA1A6WCI+tPu1V9qoVxgk6qlk30GL+Y+DlBVeq4Au0IN3Q0YA4Gl4QS6W2mhB3guuSxH0iF1oe3DOesd14Pe+TyTWC3X9hcRH2z6TAgx6BAA4Ol1w9j8NtDewGKOPauhMQGO0T+yU8AfNmsOzoaboru1XghCiYFl1kpTfsq1j0E1iK61H8fw9g7IfACOURUKyiym2IkwwLLrJSm/ZVrHoI6rRwaSBM9SH0u8YWYD2I8C12qvV1HCyknI7ejYNO0tufZTO13T+/i1xEtSJOmzwmxylVFACwPQWnpuMUdvZ8z6eUs4k8OMPYKZey+C4dPobf+o//9k=" alt="" />

(注:如果你实在看不懂,我再解释一下,{OΘ}可以拆成第一个位置【一定被被覆盖】和【一定不被覆盖】两种情况,所以就有了{OΘ}={ΘΘ}+{×Θ}  =>{ΘΘ}={OΘ}-{×Θ}.   接着同理对剩下的Θ,用相同的方式展开掉就行了。}

这样就转化为只有01的形式,然后用问题的1方式就能计算了,到这问题就解决了吗?然而还有一些计算上的细节问题要解决。

  所以我们继续尝试计算{ΘΘΘ},来说明这个问题

经过一番费力的展开,你会得到{ΘΘΘ}={OOO} - {OO×} - {O×O} + {O××} - {×OO} + {×O×} + {××O} -{×××} .

你观察一下就会发现,实际上发现,其实就是

其中r(A1,A2,A3) 为A1,A2,A3中x的个数。  说白就是类似多项式(1+(-x))^m  的展开形式。

在这里我们有两个重要的结论:

  • 结论一:答案一定能表示如下形式(因为任意一个{A1,A2,A3}肯定是x^m 形式)。

    

  • 结论二:暴力枚举情况,要枚举2^n种可能,所以暴力是不可行的

问题3:在只有2的情况下,怎么在多项式时间里计算n个2的方案数?

  根据问题2的结论1,对dp初步方案是用dp[i][j],代表{i个Θ}中 j^m的系数。 然后答案就是Σdp[i][j]* j^m,

然后来考虑一下转移:{i个Θ}={(i-1个Θ) +O}-{i-1个Θ) +×}。

你自行思考一下就会发现,这个{ (i-1个Θ) +×} 不就是等于{i-1个Θ} 吗?  因为这个尾巴上的×,对可选区间数莫有虾米贡献,(因为x是不能选的,挂不挂在尾巴上没差)。

而这个(i-1个Θ) +O} 好像不太能转化成和{i-1个Θ}有关形式,因为每种情况的可选区间数,都可以额外增加【最后一个O贡献的可选区间的数】=【右端点为n的可选区间的数量】=【i - 上一个1的位置】。但是这个上一个1的位置,对于不同情况是不一样的。(例如{OO}=3^m  而再加个O话,{OOO}=(3+3)^m ,而对于{O×}=1^m,再加个O,{O×O}=(1+1)^m,)

  因此我还需要对dp状态加个维度,我们用dp[i][j][k]代表{i个Θ}展开中,最后一个×出现的位置为j的方案中  k^m的系数。 然后答案就是Σdp[i][j][k]* k^m,

现在我在来考虑一下dp方程这么转移。我们要加上{(i-1个Θ) +O}的方案数,减掉{i-1个Θ) +×}的方案数,所以有:

  • 当尾巴加O不改变最后一个1位置,但是改变可选区间数:

    for(j=0,j<i;j++)

     

  • 当尾巴加x时,所有转移到这个状态的,【最后一个1的位置】都要改成i:

    

到此转移就完成了,然后你会发现,这个算法是n^4。但是常数很小,然后题目有1000组数据,其中包含50组大数据_(¦3」∠)_,写挫就可能惨遭卡常。

顺便给个样例,100个2 ,m=1e9  的方案数mod 1e9+7  的结果是388544367。

问题四 在0,1,2三种数字都考虑的情况,状态该怎么转移?。

其实0,1转移方法和上面类似的,

  • 所以遇到1,因为{(i-1个Θ) +1}={(i-1个Θ) } ,所以连动都不要动,但是注意需要记这个1的位置,因为在计算右端点为n的可选区间的数量会用到。
  • 而遇到0时,所有情况下k那个维度都要加上【i - 上一个1的位置】偏移量,所以要讨论一下这个1是从2变来,还是真正的1。
  • 然后遇到2,转移是和问题三一样的,只不过也要注意一下,计算偏移量时的这个1是从2变来,还是真正的1就行了

最后,你发现这个毒瘤题还会有爆内存的风险,需要优化掉一维的空间。而且可能还要和卡常斗智斗勇。

所以再仔细观察一下,你发现这两种转移其实就是两种简单的操作:一种是数组下标偏移,一种是求j那维的前缀和。

因此当个二维数组写的时候:遇到1,不做任何操作。遇到0时只累加偏移量。遇到2,枚举j求个前缀和,求玩在计算2带来的偏移量。

最后在计算答案的时候,把偏移量代入就行了

AC代码如下:

 #include<cstdio>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
#define ll long long
const int mod=1e9+;
inline int max(const int &x,const int &y)
{
return x>y?x:y;
}
int dp[][];
int d[];
int xx[];
int a[];
ll temp[];
inline ll quickpow(ll a, ll n)
{
ll ans=;
while(n)
{
if(n&)
ans=ans*a%mod;
n>>=;
a=a*a%mod;
}
return ans;
}
int main()
{
int n,m,t,r,i,mx;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
r=;
mx=;
a[]=;
for(i=; i<=n; i++)
{
scanf("%d",&a[i]);
if(a[i]==)
{
r=i;
}
mx+=i-r;
}
for(i=; i<=n; i++)
memset(dp[i],,sizeof(dp[i][])*(mx+));
memset(xx,,sizeof(xx));
memset(d,,sizeof(d));
dp[][]=;///注意啥都不选也有一种方案。
r=;
mx=;
for(i=; i<=n; i++)
{
if(a[i]==)///1的时候屁事都不干
{
r=i;
}
else
{
if(a[i]==)///0的时候累加偏移量
{
for(int j=; j<i; j++)
{
xx[j]+=i-max(j,r);
}
}
else if(a[i]==)
{
for(int j=; j<i; j++)
{
if(a[j]==)
{
mx=d[j];
d[i]=max(d[i],mx+xx[j]);///d[i]是可能有值的系数的宽度。
for(register int k=xx[j]; k<=mx+xx[j]; k++)///这里注意一下j带有的偏移量,所以不能直接 dp[i][k]-=dp[j][k],而是应该dp[i][k]-=dp[j][k-xx[j]];,
{
dp[i][k]-=dp[j][k-xx[j]];
if(dp[i][k]<)
dp[i][k]+=mod;
}
}
}
for(int j=; j<i; j++)///把2当0时累加偏移量。注意这个for是不能和上一个for交换位置,如果写个三维数组的,再改成二维数组就会知道为什么。
{
xx[j]+=i-max(j,r);
}
}
}
}
long long ans=;
mx=;
for(i=; i<=n; i++)
{
mx=max(mx,d[i]+xx[i]);
}
for(i=; i<=mx; i++)///预处理一下所有数的次幂。
{
temp[i]=quickpow(i,m);
}
for(int i=; i<=n; i++)
{
if(a[i]==)
{
for(int j=; j<=d[i]; j++)
{
ans+=dp[i][j]*temp[j+xx[i]]%mod;
ans%=mod;
}
}
}
if(ans<)
ans+=mod;
printf("%lld\n",ans);
}
return ;
}

青岛现场赛G题(zoj上2650ms,2696kb)

ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)的更多相关文章

  1. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  2. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  3. 2018 ACM 网络选拔赛 青岛赛区

    一些题目的代码被网站吞了…… Problem B. Red Black Tree http://acm.zju.edu.cn/onlinejudge/searchProblem.do?contestI ...

  4. ICPC 2018 徐州赛区网络赛

    ACM-ICPC 2018 徐州赛区网络赛  去年博客记录过这场比赛经历:该死的水题  一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进.     D. Easy Math 题意:   ...

  5. LeetCoded第25题题解--K个一组翻转链表--java--链表

    链表 单链表:链表中的每个元素实际上是一个单独的对象,而所有对象都通过每个元素的引用字段链接在一起. 双链表:与单链表不同的是,双链表的每个节点都含有两个引用字段. 链表优点 灵活分配内存空间 能在O ...

  6. ACM-ICPC 2018青岛网络赛-H题 Traveling on the Axis

    题目:略(不知道怎么从ZOJ搬题) 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 把这题的每个点分成两种情况 ...

  7. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛D-80 Days--------树状数组

    题意就是说1-N个城市为一个环,最开始你手里有C块钱,问从1->N这些城市中,选择任意一个,然后按照顺序绕环一圈,进入每个城市会有a[i]元钱,出来每个城市会有b[i]个城市,问是否能保证经过每 ...

  8. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(尺取)题解

    题意:n个城市,初始能量c,进入i城市获得a[i]能量,可能负数,去i+1个城市失去b[i]能量,问你能不能完整走一圈. 思路:也就是走的路上能量不能小于0,尺取维护l,r指针,l代表出发点,r代表当 ...

  9. ACM-ICPC 2018 青岛赛区现场赛 K. Airdrop && ZOJ 4068 (暴力)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4068 题意:吃鸡游戏简化为二维平面上有 n 个人 (xi,yi) ...

随机推荐

  1. React setState更新数组中的某个元素Element item

    var items = this.state.items; items[i].status = 'doing'; this.setState({ items: items }); //this.sta ...

  2. JavaScript的消息机制

    JavaScript本身是单线程的,但它却是事件驱动的.类似Windows窗体应用程序,它也需要消息队列机制来实现.程序的执行并不是连续的,绝大多数时间都在等待消息.每次执行执行程序都是在响应消息,这 ...

  3. 分布式集群Session原理及实现共享

    1.什么是Session/Cookie? 用户使用网站的服务,基本上需要浏览器与Web服务器的多次交互.HTTP协议本身是无状态的,当用户的第一次访问请求结束后,后端服务器就无法知道下一次来访问的还是 ...

  4. BeatSaber节奏光剑插件开发官方教程1-创建一个插件模板

    原文:https://wiki.assistant.moe/modding/intro 一.简介 Beat Saber 开发环境:unity2018.C#..NET framework 4.6. 此教 ...

  5. Spring boot + jdbc学习笔记

    pom.xml: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...

  6. 用adb 启动camera

    adb shell am start -a android.media.action.STILL_IMAGE_CAMERA  启动camera adb shell input keyevent 27 ...

  7. 配置Nginx反向代理服务器

    一.主要配置文件:/etc/nginx/nginx.conf 内容如下图 扩展配置文件:/etc/nginx/conf.d/*.conf 图中的主配置文件的末尾,加载所有扩展配置文件里面以.conf结 ...

  8. LAMP服务器的搭建

    LAMP是一组构建Web应用平台的开源软件解决方案,它是一个开源套件组合.其中L:linux,A :Apache HTTP服务器,M : MySQL或MariaDB,P : perl或Python.这 ...

  9. 【bzoj3170】[Tjoi2013]松鼠聚会(数学题)

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=3170 这道题要在n个点中求一个点使其他点到该点的切比雪夫距离最小. 有个结论:$ (x ...

  10. Graph_Master(连通分量_B_Trajan+完全图)

    hdu_4635 题目大意:给出一张DAG(n个点,m条边),求出能加的最大边数,使得该图无重边,无自环,非强连通. 题解:这题题面很好理解,也没有什么很难的点,主要是如何求出最大边数需要动点脑筋.首 ...