Luogu P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)
这是一道典型的记忆化搜索题。
f[x][y]表示以x,y为右下角的方案数。
code:
#include <cstdio>
#define mod 1000000007
using namespace std;
int n,m,k,a[][],f[][];
int DP(int x,int y){
if(f[x][y])return f[x][y];
for(int i=;i<x;i++)
for(int j=;j<y;j++)
if(a[i][j]!=a[x][y])f[x][y]+=DP(i,j),f[x][y]%=mod;
return f[x][y];
}
int main(){
scanf("%d %d %d\n",&n,&m,&k);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)scanf("%d",&a[i][j]);
f[][]=;
printf("%d",DP(n,m));
return ;
}
Luogu P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)的更多相关文章
- 洛谷 P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)
P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold) 就像人类喜欢跳格子游戏一样,FJ的奶牛们发明了一种新的跳格子游戏.虽然这种接近一吨的笨拙的动物玩跳格子游戏几 ...
- 洛谷P3120 [USACO15FEB]牛跳房子(动态开节点线段树)
题意 题目链接 Sol \(f[i][j]\)表示前\(i\)行\(j\)列的贡献,转移的时候枚举从哪里转移而来,复杂度\(O(n^4)\) 然后考虑每一行的贡献,动态开节点线段树维护一下每种颜色的答 ...
- Luogu P3033 [USACO11NOV]牛的障碍Cow Steeplechase(二分图匹配)
P3033 [USACO11NOV]牛的障碍Cow Steeplechase 题意 题目描述 --+------- -----+----- ---+--- | | | | --+-----+--+- ...
- Luogu P2966 [USACO09DEC]牛收费路径Cow Toll Paths
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...
- 【洛谷】2990:[USACO10OPEN]牛跳房子Cow Hopscotch【单调队列优化DP】
P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing ...
- 洛谷P3120 [USACO15FEB]Cow Hopscotch
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented ...
- P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold
P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold我比赛的时候A了,luogu上25分,QAQ,又憨又傻的200+代码,我为什么要干电脑干的事情,无语了.如果左边 ...
- 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- Cow Hopscotch
Cow Hopscotch 题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have inv ...
随机推荐
- webpack学习(五)配置详解
配置详解 //使用插件html-webpack-plugin打包合并html //使用插件extract-text-webpack-plugin打包独立的css //使用UglifyJsPlugin压 ...
- Steeltoe
谈谈Circuit Breaker在.NET Core中的简单应用 http://www.cnblogs.com/catcher1994/p/8975192.html 前言 由于微服务的盛行,不少公司 ...
- perl学习---控制:unless,until,next,redo,last
1.1.unless unless 的含义是:除非条件为真,否则执行块中的代码,和if正好相反 unless($fred=~ /^[A-Z_]\w*$/i){ print “The value of ...
- BZOJ2301:[HAOI2011]Problem b(莫比乌斯反演,容斥)
Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...
- es6之类与对象
一.类的定义 class Parent{ constructor(name="mukewang"){ this.name=name; } } let v_parant=new Pa ...
- nodejs 做的带管理后台的东东,主要学习到 ....我忘了学到什么了
效果 http://www.steel-pot.com/ function handleStr(str,isHtml,callback) { if(!isHtml) { callback(str); ...
- Selenium基本用法以及元素定位
一.Selenium 简介 Selenium是ThroughtWorks公司一个强大的开源Web功能测试工具系列,提供一套测试函数,用于支持Web自动化测试.函数非常灵活,能够完成界面元素定位.窗口跳 ...
- DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描
DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之Spr ...
- Eclipse新导入的项目中ctrl+点击指定方法名或类名没有反应,不能跳转问题
项目没有转成java项目 解决方法:右击项目名---选择properties----点击Project Facets,这样就可以实现ctrl+左键点击跳转了. 转成java项目后会报错 解决办法:选中 ...
- input 输入的一些限制说明
input输入框 只能输入 数字可以有小数点 <input class="form_text" id="purchasePrice" name=" ...