• [POJ3254]Corn Fields


    [POJ3254]Corn Fields

    试题描述

    Farmer John has purchased a lush new rectangular pasture composed of (M) by (N) ((1 le M le 12; 1 le N le 12)) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.

    Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.

    (N imes M)($ le 12$)的棋盘

    每个格子有两种状态,可以放牧和不可以放牧,可以放牧用 1 表示,否则用 0 表示

    在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相邻

    问有多少种放牛方案

    一头牛都不放也是一种方案,答案对 (100000000) 取模

    输入

    Line (1): Two space-separated integers: (M) and (N)

    Lines (2)..(M+1): Line (i+1) describes row (i) of the pasture with (N) space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)

    输出

    Line (1): One integer: the number of ways that FJ can choose the squares modulo (100,000,000).

    输入示例

    2 3
    1 1 1
    0 1 0
    

    输出示例

    9
    

    数据规模及约定

    见“试题描述

    题解

    轮廓线 dp,直接写吧。

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cctype>
    #include <algorithm>
    using namespace std;
    #define rep(i, s, t) for(int i = (s); i <= (t); i++)
    #define dwn(i, s, t) for(int i = (s); i >= (t); i--)
    
    int read() {
    	int x = 0, f = 1; char c = getchar();
    	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
    	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
    	return x * f;
    }
    
    #define maxn 15
    #define maxs 4096
    #define MOD 100000000
    
    int n, m, f[maxn][maxn][maxs];
    bool Map[maxn][maxn];
    
    #define fnxt f[j==m?i+1:i][j==m?1:j+1]
    
    int main() {
    	n = read(); m = read();
    	rep(i, 1, n) rep(j, 1, m) Map[i][j] = read();
    	
    	int all = (1 << m) - 1;
    	f[1][1][0] = 1;
    	rep(i, 1, n) rep(j, 1, m) rep(s, 0, all) {
    		int up = s >> m - 1 & 1, lft = s & 1;
    		if(!up && (j == 1 || !lft) && Map[i][j]) (fnxt[(s<<1&all)|1] += f[i][j][s]) %= MOD;
    		(fnxt[s<<1&all] += f[i][j][s]) %= MOD;
    	}
    	
    	int ans = 0;
    	rep(s, 0, all) (ans += f[n+1][1][s]) %= MOD;
    	printf("%d
    ", ans);
    	
    	return 0;
    }
    
  • 相关阅读:
    Response 文件下载
    Tomcat Servlet
    Junit 反射 注解
    Stream流 方法引用
    函数式接口
    网络编程
    缓冲流、转换流、序列化流、打印流
    字节流 字符流
    File类 递归
    线程池 Lambda表达式
  • 原文地址:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/7997410.html
Copyright © 2020-2023  润新知