这个……真心看不出来是个DP,我在树状数组的康庄大道上欢快的奔跑了一下午……看了题解才发现错的有多离谱. 参考:http://www.cnblogs.com/kuangbin/archive/2012/11/11/2765329.html #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define LL long long int using nam…
题目链接:hdu 4455 Substrings 题目大意:给出n,然后是n个数a[1] ~ a[n], 然后是q次询问,每次询问给出w, 将数列a[i]分成若干个连续且元素数量为w的集合,计算每个集合中出现的数字种类,输出总和. 解题思路:一开始想到遍历的算法,保持集合元素为w,每次剔除最前一个,加入一个,移动集合,维护数字种类,这种算法的复杂度为o(n^2), 但是超时了,后来看了下题解,dp[i] = dp[i - 1] + sum[i] - cnt; http://blog.csdn.n…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1727    Accepted Submission(s): 518 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1161    Accepted Submission(s): 351 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3269    Accepted Submission(s): 999 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is t…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3240    Accepted Submission(s): 990 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is t…
XXX has an array of length n. XXX wants to know that, for a given w, what is the sum of the distinct elements' number in all substrings of length w. For example, the array is { 1 1 2 3 4 4 5 } When w = 3, there are five substrings of length 3. They a…
题意: 给一串数字,给q个查询,每次查询长度为w的所有子串中不同的数字个数之和为多少. 解法:先预处理出D[i]为: 每个值的左边和它相等的值的位置和它的位置的距离,如果左边没有与他相同的,设为n+8(看做无穷). 考虑已知w=k的答案,推w = k+1时,这时每个区间都将增加一个数,即后n-k个数会增加到这些区间中,容易知道,如果区间内有该数,那么个数不会加1,,即D[i] > k时,结果++,即查询后n-k个数有多少个D[i] > k 的数即为要加上的数,然后最后面还会损失一个区间,损失的…
5000ms的时限,还挺长的.算法是DP.思路是找到ans[1..n]的结果,然后Query就容易做了.问题是怎么DP?考虑:1 1 2 3 4 4 5w=1: 7, 7 = 1 * 7w=2: 10,10 = |{1,1}|+|{1,2}|+|{2,3}|+|{3,4}|+|{4,4}|+|{4,5}|=1+2+2+2+1+2=10w=3: 12,  12 = |{1,1, 2}|+|{1,2, 3}|+|{2,3, 4}|+|{3,4, 5}|+|{4,4, 5}|...观察w=3如何在w=…
http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to encourage people to do sports. He has got trouble in choosing the route. There are N houses and N - 1 roads in his village. Each road connects two houses,…