code forces 1051 d
看的这个题解:http://www.cnblogs.com/tobyw/p/9685639.html
写的比较清楚。
矩阵类型的计数题
比赛时感觉就像是个dp,然后就跳过了。
现在看着题解写一下,感觉还算可以理解。但是没有dp的思维啊,肯定想不出来的。。
#include <bits/stdc++.h> using namespace std; long long dp[][][]; const long long mod = ;
int main() { long long n,k; cin>>n>>k; memset(dp,,sizeof(dp)); dp[][][] = ; //
dp[][][] = ; //
dp[][][] = ; //
dp[][][] = ; //11 //cout<<k<<endl;
for(int i = ; i <= n; i++) {
// i列最多i * 2 个联通块
for(int j = ; j <= (i << ); j++) {
//cout<<dp[n][k][0]<<' '<<dp[n][k][1]<<' '<<dp[n][k][2]<<' '<<dp[n][k][3]<<endl;
//cout<<j<<endl;
// 这一列填00的
dp[i][j][] = dp[i - ][j][] + dp[i - ][j][] + dp[i - ][j][] + dp[i - ][j - ][];
dp[i][j][] %= mod; // 填01
dp[i][j][] = dp[i - ][j - ][] + dp[i - ][j][] + dp[i - ][j - ][] + dp[i - ][j - ][];
dp[i][j][] %= mod; // 填10
dp[i][j][] = dp[i - ][j - ][] + dp[i - ][j - ][] + dp[i - ][j][] + dp[i - ][j - ][];
dp[i][j][] %= mod; // 填11
dp[i][j][] = dp[i - ][j - ][] + dp[i - ][j][] + dp[i - ][j][] + dp[i - ][j][];
dp[i][j][] %= mod; }
} long long ans = ;
//cout<<dp[n][k][0]<<' '<<dp[n][k][1]<<' '<<dp[n][k][2]<<' '<<dp[n][k][3]<<endl;
ans = ans + dp[n][k][] + dp[n][k][] + dp[n][k][] + dp[n][k][];
ans = ans % mod;
//cout<<ans<<endl;
printf("%I64d\n", ans); return ;
}
code forces 1051 d的更多相关文章
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- code forces 999C Alphabetic Removals
C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...
- code forces 382 D Taxes(数论--哥德巴赫猜想)
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
- code forces Watermelon
/* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...
- code forces Jeff and Periods
/* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...
随机推荐
- 8 Java 归并排序(MergerSort)
图片素材与文字描述来自:尚硅谷-韩顺平数据结构与算法. 1.基本思想 归并排序是利用归并的思想实现的排序方法,该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divi ...
- 10.字符串str的语法
1).字符串的索引以及切片 s = 'ABCDLSESRF' #索引 s1 = s[0] print(s1) #A s2 = s[2] print(s2) #C s3 = s[-1] print(s3 ...
- 清理数据库事务——SQL语句
清除流程内部的所有相关数据 eg1: declare @procedureTemp table ( [ProcedureCode] varchar(10) ) declare @ProcedureCo ...
- js函数式编程(三)-compose和pointFree
compose即函数嵌套组合 组合compose在第一篇已经初见端倪,可以感受一下.compose函数的实现用闭包的方法.不完善实现如下: const compose = (f, g) => { ...
- js的工厂模式
工厂模式: 什么叫工厂模式,工厂就是大家大脑里想的那样,一个流水线作业的一个东西,只需要满足刚需就可以了,一个人,只干一件事,最后串起来,就是一个事件. 首先需要说一下工厂模式.工厂模式根据抽象程度的 ...
- PAT 乙级 1005
题目 题目地址:PAT 乙级 1005 题解 本题主要就在于将一个数的一系列计算结果不重复地存储起来并便于检索,考虑到STL中的集合有相似的特性,使用set可以有效地简化代码和运算. 过程如下: (初 ...
- MYSQL中批量替换某个字段的部分数据
1.修改字段里的所有含有指定字符串的文字 UPDATE 表A SET 字段B = replace(字段B, 'aaa', 'bbb') example: update table set url= ...
- DNS服务-主从架构搭建
为了网站的可靠性,通常都会有多个DNS服务器,万一DNS服务器宕机了,可以实现DNS服务器容错 通常都会有一个主DNS服务器,后面配若干个辅助DNS服务器,这个主DNS服务器的数据库会同步给其他的DN ...
- C++简单年月日的功能实现
// C++年月日判断初步代码 #include <iostream> using namespace std; class Data { int year; int month; int ...
- HTML 文件类表单元素如何限制上传类型,Accept属性设置
需求描述:简单的控制file的选择类型 解决方法:使用HTML input file 的accept属性控制 实例: <form action="demo_form.asp" ...