Vijos p1002 crossing the river (noip increases the group by 2005)

Source: Internet
Author: User

Link: Https://www.vijos.org/p/1002


Analysis:

If p * x + (p + 1) * Y = Q (Q can be jumped to any position when the distance P and p + 1 are used ), Q ≥ p * (P-1) is a certain solution.
Because the range given in the question is 1 ≤ S ≤ T ≤ 10, when the distance between the adjacent two stones is not less than 8*9 = 72, then, we can think that the distance between them is 72. In this way, the range of the original question l is reduced to 100*72 = 7200, and the dynamic planning algorithm is completely sufficient.

However, when S = t, the above equations cannot be used. In this case, you only need to count the number of stones whose coordinates are multiples of s among all stones.


Note::

1. compression is required when DP is used.

2. Special answer s = T


Code:

# Include <istream> # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; # define min (X, y) (x <Y? X: Y) # define INF 1e7int DP [100010]; int dd [100010]; int dis [105]; int main () {int L, S, T, M; int I, j; scanf ("% d", & L, & S, & T, & M); for (I = 1; I <= m; ++ I) scanf ("% d", & dis [I]); int ans = 0; If (S = T) {for (I = 1; I <m; ++ I) if (DIS [I] % s = 0) ++ ans ;} else {dis [0] = 0; sort (DIS, DIS + m + 1); memset (DD, 0, sizeof (dd); for (I = 1, j = 0; I <= m; ++ I) {If (DIS [I]-Dis [I-1])> 100) J + = 100; else J + = dis [I]-Dis [I-1]; dd [J] = 1;} int K = J + 100; dd [0] = 0; for (I = 1; I <= K; ++ I) {DP [I] = inf; For (j = s; j <= T; ++ J) {if (I <j) break; DP [I] = min (DP [I], DP [I-j] + dd [I]);} ans = DP [k];} printf ("% d \ n", ANS); Return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.