题意:

给一个n*n(n<=50)的棋盘,放上k个主教(斜走),求能放置的种类总数。


Solution :

SGU 220,加个高精度就好了。

code

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std; string f[][][], ans;
int tem[];
int n, k, tol; string add (string a, string b) {
string c;
int s[] = {};
for (int i = ; i < a.size(); i++) s[i] += a[i] - '';
for (int i = ; i < b.size(); i++) s[i] += b[i] - '';
int len = max (a.size(), b.size() );
for (int i = ; i < len; ++i) {
if (s[i] >= ) {
s[i + ] += s[i] / , s[i] = s[i] % ;
if (i + == len) len++;
}
c += '' + s[i];
}
return c;
}
string operator * (string a, int k) {
string c;
int len = a.size(), x = ;
for (int i = , tem; i < len; ++i) {
tem = (a[i] - '') * k + x;
c += '' + tem % ;
x = tem / ;
}
for (; x; x /= ) c += '' + x % ;
return c;
}
string operator * (string a, string b) {
string c;
int s[] = {};
for (int i = ; i < a.size(); ++i)
for (int j = ; j < b.size(); ++j)
s[i + j] += (a[i] - '') * (b[j] - '');
int len = a.size() + b.size() - ;
for (int i = ; i < len; ++i) {
if (s[i] >= ) {
s[i + ] += s[i] / , s[i] %= ;
if (i + == len) len++;
}
c += '' + s[i];
}
return c;
}
void make (int x) {
tol = ;
for (int t = x; t <= n; t += ) {
tem[++tol] = t;
if (t != n) tem[++tol] = t;
}
f[x - ][][] = "";
string t;
for (int i = ; i <= tol; i++)
for (int j = ; j <= k; j++)
if (tem[i] >= j) {
if (j > ) t = f[x - ][i - ][j - ] * (tem[i] - j + );
else t = "";
f[x - ][i][j] = add (f[x - ][i - ][j] , t );
}
}
int main() {
ios::sync_with_stdio ();
cin >> n >> k;
make ();
make ();
ans = "";
for (int i = ; i <= k; i++)
ans = add (ans , f[][tol][i] * f[][ * n - - tol][k - i]);
while (* (ans.end() - ) == '' && ans.size() > ) ans.erase (ans.end() - );
reverse (ans.begin(), ans.end() );
cout << ans ;
}

SGU 221.Big Bishops(DP)的更多相关文章

  1. SGU 220.Little Bishops(DP)

    题意: 给一个n*n(n<=10)的棋盘,放上k个主教(斜走),求能放置的种类总数. Solution: 一眼看上去感觉是状压DP,发现状态太多,没办法存下来... 下面是一个十分巧妙的处理: ...

  2. SGU 390-Tickets(数位dp)

    题意:有标号l-r的票,要给路人发,当给的票的编号的各数位的总和(可能一个人多张票)不小k时,才开始发给下一个人,求能发多少人. 分析:这个题挺难想的,参考了一下题解,dp[i][sum][left] ...

  3. SGU 199 Beautiful People(DP+二分)

    时间限制:0.25s 空间限制:4M 题意: 有n个人,每个人有两个能力值,只有一个人的两个能力都小于另一个的能力值,这两个人才能共存,求能同时共存的最大人数. Solution: 显然这是一个两个关 ...

  4. SGU 134.Centroid( 树形dp )

    一道入门树dp, 求一棵树的重心...我是有多无聊去写这种题...傻X题写了也没啥卵用以后还是少写好.. ----------------------------------------------- ...

  5. sgu 131 状压DP

    棋盘覆盖(二) 时间限制:1000 ms  |  内存限制:65535 KB     描述 The banquet hall of Computer Scientists' Palace has a ...

  6. [LeetCode] 221. 最大正方形(DP)

    题目 在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积. 示例: 输入: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 输出: 4 ...

  7. SGU 144. Meeting 概率dp 几何概率分布 难度:0

    144. Meeting time limit per test: 0.25 sec. memory limit per test: 4096 KB Two of the three members ...

  8. SGU 乱乱开

    本解题报告 乱抄,乱写,随性随心,不喜多喷! SGU 142: 思路:一个string的字串不会超过2^20个,我们枚举出来就好了. 我出错点:数组RE #include<stdio.h> ...

  9. HDU-4507-吉哥系列故事-恨7不成妻

    题目描述 单身! 依然单身! 吉哥依然单身! DS级码农吉哥依然单身! 所以,他生平最恨情人节,不管是214还是77,他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 ...

随机推荐

  1. nginx -- 安装配置Nginx

    安装说明 系统环境:CentOS-6.3 软件:nginx-1.2.6.tar.gz 安装方式:源码编译安装  安装位置:/usr/local/nginx  下载地址:http://nginx.org ...

  2. 教程:在 VM Depot 中查找 Azure 可用的虚拟机镜像

     发布于 2014-07-08 作者 陈 忠岳 对于 Azure 的社区管理虚拟机资源库--VM Depot--的用户来说,网站的搜索功能已得到极大的改善.这一搜索能力的增强,可以帮助用户更容易地 ...

  3. 【转】Ubuntu14.04搭建安装svnserver

    原文网址:http://www.cnblogs.com/blfshiye/p/5168028.html 前两天,公司准备搭建一个svnserver,供大家使用.于是.就先装了一个Ubuntu系统,然后 ...

  4. 区分execl与system——应用程序中执行命令

    execl:相关函数:fork, execle, execlp, execv, execve, execvp表头文件:#include <unistd.h>函数定义:int execl(c ...

  5. (转载)mysql中limit用法

    (转载)http://hi.baidu.com/sppeivan/item/e45179375d6778c62f8ec221   mysql中limit用法 使用查询语句的时候,经常要返回前几条或者中 ...

  6. Java中的包

    包:定义包用package关键字. 1:对类文件进行分类管理. 2:给类文件提供多层名称空间. 如果生成的包不在当前目录下,需要最好执行classpath,将包所在父目录定义到classpath变量中 ...

  7. openstack grizzly版network网络节点安装

    版本以及源的配置和控制节点一致 1.安装完操作系统已经apt源配置完成之后,一定要执行 apt-get update root@cloud:~# mv /etc/apt/sources.list /e ...

  8. openStack 性能开测

  9. Shtirlits - SGU 125(搜索)

    题目大意:B[i, j]表示周围有多少个比它大的数,能否用B数组构造出一个A数组,如果不能输出“NO SOLUTION”. 分析:数据规模比较小,可以直接暴力枚举每个点的值. 代码如下: #inclu ...

  10. tl;drLegal ——开源软件license的搜索引擎

    TLDRLegal - Open Source Licenses Explained in Plain English可以很方便查询各个开源license的总结(能做什么,不能做什么),还能比较不同的 ...