【POJ3254】Corn Fields

2024-08-31 17:08
文章标签 corn fields poj3254

本文主要是介绍【POJ3254】Corn Fields,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Corn Fields
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8670 Accepted: 4622

Description

Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 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.

Input

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)

Output

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

Sample Input

2 3
1 1 1
0 1 0

Sample Output

9

Hint

Number the squares as follows:
1 2 34  

There are four ways to plant only on one squares (1, 2, 3, or 4), three ways to plant on two squares (13, 14, or 34), 1 way to plant on three squares (134), and one way to plant on no squares. 4+3+1+1=9.

Source

USACO 2006 November Gold


1.判断A < B 使用 A 并(~B)   = 0.


#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
using namespace std;

const int mod = 100000000;
int N,M;
int state[2 << 13];
int dp[13][2<<13];
int cur[13];
int stanums;
int upp;

void init()
{
    stanums =  0;
    for(int i=0;i<upp;i++)
    {
        if((i & (i<< 1)))
        {
           
        }
        else
        {
             state[stanums ++] = i;
        }
    }
}

bool fit(int idx,int i)
{
    if((state[idx] & cur[i]) == 0) return true;

    return false;
}
int main()
{
    freopen("1.txt","r",stdin);
    while(scanf("%d%d",&N,&M) != EOF)
    {
        memset(dp,0,sizeof(dp));
        upp = (1 << M);
        init();
        memset(cur,0,sizeof(cur));

        int tmp;
        for(int i=1;i<=N;i++)
            for(int j=1;j<=M;j++)
        {
            scanf("%d",&tmp);
            if(tmp == 0)
            {
                //scanf("")
                cur[i] += (1 << (M-j));
            }
        }

        for(int i=0;i<stanums;i++)
        {
            if(fit(i,1))
                dp[1][i] = 1;

        }


        for(int i=2;i<=N;i++)
        {
            for(int j=0;j<stanums;j++)
            {
                if(!fit(j,i)) continue;
                for(int k=0;k<stanums;k++)
                {
                    if(!fit(k,i-1)) continue;


                if(state[j] & state[k]) continue;

                dp[i][j] = (dp[i][j] + dp[i-1][k]) % mod;
                }
            }
        }
        int ans = 0;
        for(int i=0;i<stanums;i++)
        {
            ans = (ans + dp[N][i]) % mod;
        }

        printf("%d\n",ans);
    }
    while(1);
    return 0;
}



这篇关于【POJ3254】Corn Fields的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1124485

相关文章

Signed distance fields (SDFs) and Truncated Signed Distance Field(TSDF)

1. Signed distance fields (SDFs) 笔记来源: [1] Signed distance fields (SDFs) [2] Signed Distance Function (SDF): Implicit curves or surfaces [3] Ray Marching and Signed Distance Functions [4] Truncated S

NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis 精读

1 传统视图合成和NeRF(Neural Radiance Fields) 1.1 联系 传统视图合成和NeRF的共同目标都是从已有的视角图像中生成新的视角图像。两者都利用已有的多视角图像数据来预测或合成从未见过的视角。 1.2 区别 1.2.1 几何表示方式 传统视图合成:通常使用显式几何模型(如深度图、网格、点云)或其他图像处理方法(如基于图像拼接或光流的方法)来生成新的视图。这些

corn表达式规则

cron的表达式被用来配置CronTrigger实例。 cron的表达式是字符串,实际上是由七子表达式,描述个别细节的时间表。这些子表达式是分开的空白,代表: 1. Seconds 2. Minutes 3. Hours 4. Day-of-Month 5. Month 6. Day-of-Week 7. Year (可选字段) 例 "0 0 12 ? * WED" 在每星期三下午

poj3254--Corn Fields(状压dp)

Corn Fields Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 8512 Accepted: 4540 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤

POJ 3083Children of the Candy Corn(DFS*2+BFS)

题目地址:http://poj.org/problem?id=3083 这道题整体思路并不难,但一些细节方面有点难想。。主要是容易写的太麻烦,太乱。。虽然我的代码也比较长,但是思路还是挺清晰的(基本就是把上一段的复制下来稍微改改。。)。但是有些细节方面一开始想错了,导致调试了很长时间。主要思路是记录4个方向然后改变方向走。 题目意思是输出往左绕的步数与往右绕的步数,还有最短步数。前两个用DFS

NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis 翻译

NeRF:将场景表示为用于视图合成的神经辐射场 引言。我们提出了一种方法,该方法通过使用稀疏的输入视图集优化底层连续体场景函数来实现用于合成复杂场景的新视图的最新结果。我们的算法使用全连通(非卷积)深度网络来表示场景,其输入是单个连续的5D坐标(空间位置(x,y,z)和观察方向(θ,φ)),其输出是该空间位置处的体积密度和与观察相关的发射辐射。我们通过查询沿着相机光线的5D坐标来合成视图,并使用

辐射神经场(NeRF, Neural Radiance Fields)

辐射神经场(NeRF, Neural Radiance Fields) 辐射神经场(NeRF, Neural Radiance Fields)是一种基于神经网络的方法,用于从二维图像合成高质量的三维场景。这一方法由Ben Mildenhall等人在2020年提出,利用多视角二维图像进行三维重建,生成的场景具有逼真的细节和光照效果。 NeRF的基本原理 NeRF的核心思想是通过神经网络表示场景

POJ 3254 Corn Field ( 状态压缩DP )

Corn Fields Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 8443 Accepted: 4500 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤

poj3254 Corn Fields 状压dp

Language: Default Corn Fields Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 6539 Accepted: 3482 Description Farmer John has purchased a lush new rectangular pasture composed of

poj 3254 Corn Fields(动态规划:状压DP)

题意是给出一块草地,分为m*n格 某个格子为1代表可以养牛,为0代表不可以养牛 相邻的草地不可以同时养牛 问有多少种放牛的方法? 看着别人的解题报告写的 因为相邻草地不可以同时放牛,所以我们保存可以放牛对应的状态 竖着相邻的草地也不可以同时放牛,所以如果同一列相邻两行&为真,不可以放牛 同时对于当前为0的草地也不可以放牛 把这三种情况剔除,就可以得到结果 状态转移方程为:dp[i