HDU 4925 Apple Tree (inference)

Source: Internet
Author: User

HDU 4925 Apple Tree

Topic links

Test instructions: to a m*n matrix tree, each location can choose to plant trees or fertilization, if the location of the seed can not be fertilized, if fertilization can let the surrounding fruit production by 2, ask the maximum benefit

Train of thought: The inference is certainly the fruit tree and the fertilizer crosses the good, resembles the chess chessboard, the black kind, the white fertilization, because the lattice number is not many, goes directly enumerates each position to be able. If the problem is more than the number of words, can actually be introduced Formula One step to get the answer

Code:

#include <cstdio> #include <cstring>const int d[4][2] = {{0, 1}, {0,-1}, {1, 0}, {-1, 0}};int t, N, M;int main () {    scanf ("%d", &t);    while (t--) {scanf ("%d%d", &n, &m); int flag = 1;int ans = 0;for (int i = 0; i < n; i++) {for    (int j = 0; j < m; J + +) {if (flag) {    int cnt = 1;    for (int k = 0; k < 4; k++) {int xx = i + d[k][0];int yy = j + d[k][1];if (xx < 0 | | xx >= n | | yy < 0 | | yy & gt;= m) continue;cnt *= 2;    }    ans + = cnt;} Flag ^= 1;    }} 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.