07:41:02
今天是10月27日,两年前的今天第一次向WQL表白(被拒了。。喜欢直男的悲哀)
他拒绝的理由居然是 啊?我初中不谈恋爱的(那你后来瞒着我当了中央空调的事怎么解释,ZN!)
回想昨天的第一题,怎么会写不出DP方程呢,n的规模只有5000是可以开到n2的啊!有后效性没有前效性反过来DP不就没后效性了吗!?
并且要用贪心得到子问题的最优性,代码超短,核心代码如下
sort(s+1,s+n+1,cmp);
For(i,1,n){
For(j,1,n){
int fx=max(f[i-1][j],f[i-1][j-1]+s[i].v-s[i].w*(j-1));
f[i][j]=max(f[i][j],fx);
}
}
10:52:33
早上的题目还好,到现在应该是把该拿的分拿到了(T1 100 T2 100 T3 60 )
最后一题还有40分暂时没想到优秀的算法。
T1 真的就只是求了K次Djs(1<=k<=5),最后暴力 5!(120)判断最优值。
T2 树上乱搞(其实不用怎么搞),求一个DFS序后就可以直接O(1)判断并输出结果了,不过看那数据规模直接递归应该会爆栈吧,于是机智地写了人工栈。
T3 看起来像是数据结构题,但其实中间过程是需要DP的,然而我不知道怎么把DP结果和不同的询问区间结合起来,所以每次询问都要O(r-l+m)地去DP一次,所以只会有60分,后面的数据肯定会超时。
11:11:10
要不,换一个思路,不用DP?(不行,DP是肯定要的)那我要怎么维护这个区间的最优值啊????
(快点想办法,再骗几分)
11:40:09
我居然花了半个小时去对拍很有把握的T2(!?)不过这样也好,这是我第一次用并查集生成随机树的数据,不过对拍麻烦的是刚刚用了十分钟写了一个暴力程序。
T1 这种图论题没法拍了吧,那不成我还要写一次Djstrla来检验第一次写的有没有出错吗(!),拒绝。
(所以你现在是已经放弃最后一题的40分了吗)
14:26:35
与期望得分相差无几,(貌似T2不用写人工栈也行?)
T3 的正解是倍增(?)考试时完全没有向着这方面想过。
15:01:01
OK,用倍增过掉了最后一题,以后要注意了,这种不重叠区间数量的统计可以直接使用倍增
来写一下题解吧。传送门