Bzoj 1088: [SCOI2005] Minesweeper Mine (DP)

Source: Internet
Author: User

Bzoj 1088: [SCOI2005] Minesweeper Mine

Write a pitch, not a DP of the game problem
If you know the former \ (i-1\) item, the first \ ( i\) item will be known by the second column of section \ (i-1\) .
Set \ (f[i]\) is the first column of the i\ line position If there is thunder, Ray,\ (f[i] = 1\), no Thunder \ (F[i] = 0\)
\ (a[i]\) is what the topic reads.
Then the transfer equation is \ (f[i] = a[i-1]-f[i-1]-f[i-2]\)
When the limit is not met \ (F[i] < 0\) or $ f[i] > 1$
The first position is discussed. Make the above recursion.

#include <iostream>#include <cstdio>const int maxN = 10000 + 7; int f[maxN],ans,a[maxN]; inline int read() {    int x = 0,f = 1;char c = getchar();    while(c < '0' || c > '9') {if(c == '-')f = -1;c = getchar();}    while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}    return x * f;} int n;void work() {    for(int i = 2;i <= n;++ i) {        f[i] = a[i - 1] - f[i - 1] - f[i - 2];        if(f[i] < 0 || f[i] > 1) return ;    }    if(a[n] != f[n] + f[n - 1])return ;    ans ++;    return ;} int main() {    n = read();    for(int i = 1;i <= n;++ i)         a[i] = read();    for(int i = 0;i < 2;++ i)         f[1] = i,work();    printf("%d\n", ans);    return 0;}

Bzoj 1088: [SCOI2005] Minesweeper Mine (DP)

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.