Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

yi,发现楼下两只我校神牛= =,我的做法是dp + 单调栈 + 后缀数组

Posted by halfapri at 2016-08-21 07:50:33 on Problem 3415 and last updated at 2016-08-22 19:15:37
设m为第一个字符串的长度,设答案为ans。
我们现在只考虑sa[i]>m时对ans做出的贡献 (对于sa[i]<m的情况处理方法类似)。
设pre[i]为:1~i中有多少个sa[j]<m (j>=1 && j<=i)
dp[i]:表示如果是sa[i]>m的方案数。
首先我们我们用单调栈处理出一个最小的l,使得height[l+1 ~ i]>=height[i]。(明显,l=q.top(),如果q为栈的名字的话)
那么转移为:
if (height[i]<K) dp[i] = 0;
else {
    dp[i] = dp[q.top()] + (pre[i]-pre[q.top()-1]) * (height[i] - K + 1);
    if (height[q.top()]>=K) //唯一会重复算的
          dp[i] -= sa[q.top()]<m ? height[q.top()] - K + 1 : 0;
}
if (sa[i]>m) ans += dp[i];

具体代码(有组数据):https://github.com/halfapri/half/tree/master/borc/string/poj3415

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator