hdu 4925

【题意】n*m的土地里每个格子里可以种树或者施肥,每一棵树开始可以结一颗果子,他的前后左右四个格子,若施了肥就可以让他结的果翻一倍,求最多可以得到多少果子。

在每个(i+j)%2==0  的格子上种树 其他的施肥就可以了。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 using namespace std;
 5 int n,m,t;
 6 
 7 int get(int i,int j)
 8 {
 9     if(i>=0&&i<n&&j>=0&&j<m)
10         return 2;
11     return 1;
12 
13 }
14 
15 
16 int main()
17 {
18     scanf("%d",&t);
19     while(t--)
20     {
21         int ans=0;
22         scanf("%d%d",&n,&m);
23         for(int i=0; i<n; i++)
24             for(int j=0; j<m; j++)
25             {
26                 if((i+j)%2==0)
27                 {
28                     int temp=1;
29                     temp*=get(i-1,j);
30                     temp*=get(i+1,j);
31                     temp*=get(i,j-1);
32                     temp*=get(i,j+1);
33                     ans+=temp;
34                 }
35             }
36         printf("%d
",ans);
37     }
38     return 0;
39 }
原文地址:https://www.cnblogs.com/assult/p/3899410.html