Title Link: Http://codeforces.com/contest/712/problem/D
A There is a first score, A, a, B, there is a T-wheel race, each game can take [-K, K] number, ask you how many of the last a larger than B.
DPA[I][J] Indicates the number of cases where the first round of J is obtained. Since the first round is only related to the i-1 wheel, here I is optimized with a scrolling array.
If the normal practice of 3 for will time out, so to use the prefix and optimization, DPA[I][J] can be transferred by a continuous dp[i-1][x], so with Suma array access dp[i-1][x] prefix and. You can save a for.
b the same.
1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 2e5 +205; -LL dp[2][n], mod = 1e9 +7, Sum[n], dpa[2][n], suma[n]; - + intMain () - { + intA, B, K, T; Ascanf"%d %d%d%d", &a, &b, &k, &t); atA + = 1e5, B + =1e5; -dp[0][B] =1; -dpa[0][a] =1; -SUM[B] =1, Suma[a] =1; - for(inti =1; I <= t; ++i) { - for(intj =1; J < N; ++j) { indp[i%2][J] = dpa[i%2][J] =0; - } to for(intj =-k*i; J <= K*i; ++j) { + intL = max (-k* (i-1), j-k), r = min (k* (i-1), J +k); -Dp[i%2][b + j] = ((sum[r + b]-sum[l-1+ b] + dp[i%2][b + j])% mod + MoD)%MoD; theDpa[i%2][a + j] = ((Suma[r + A]-suma[l-1+ A] + dpa[i%2][a + j])% mod + MoD)%MoD; * } $ for(intj =1; J < N; ++J) {//sum will be renewed in each roundPanax NotoginsengSUM[J] = (Sum[j-1] + dp[i%2][J])%MoD; -SUMA[J] = (Suma[j-1] + dpa[i%2][J])%MoD; the } + } ALL ans =0; the for(inti =1; i < N; ++i) { +Ans = (ans + sum[i-1]*dpa[t%2][i]% MoD)%MoD; - } $printf"%lld\n", ans); $ return 0; -}
Codeforces 712 D. Memory and Scores (dp+ scrolling array + prefixes and optimizations)