SGU 221.Big Bishops(DP)
题意:
给一个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)的更多相关文章
- SGU 220.Little Bishops(DP)
题意: 给一个n*n(n<=10)的棋盘,放上k个主教(斜走),求能放置的种类总数. Solution: 一眼看上去感觉是状压DP,发现状态太多,没办法存下来... 下面是一个十分巧妙的处理: ...
- SGU 390-Tickets(数位dp)
题意:有标号l-r的票,要给路人发,当给的票的编号的各数位的总和(可能一个人多张票)不小k时,才开始发给下一个人,求能发多少人. 分析:这个题挺难想的,参考了一下题解,dp[i][sum][left] ...
- SGU 199 Beautiful People(DP+二分)
时间限制:0.25s 空间限制:4M 题意: 有n个人,每个人有两个能力值,只有一个人的两个能力都小于另一个的能力值,这两个人才能共存,求能同时共存的最大人数. Solution: 显然这是一个两个关 ...
- SGU 134.Centroid( 树形dp )
一道入门树dp, 求一棵树的重心...我是有多无聊去写这种题...傻X题写了也没啥卵用以后还是少写好.. ----------------------------------------------- ...
- sgu 131 状压DP
棋盘覆盖(二) 时间限制:1000 ms | 内存限制:65535 KB 描述 The banquet hall of Computer Scientists' Palace has a ...
- [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 ...
- 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 ...
- SGU 乱乱开
本解题报告 乱抄,乱写,随性随心,不喜多喷! SGU 142: 思路:一个string的字串不会超过2^20个,我们枚举出来就好了. 我出错点:数组RE #include<stdio.h> ...
- HDU-4507-吉哥系列故事-恨7不成妻
题目描述 单身! 依然单身! 吉哥依然单身! DS级码农吉哥依然单身! 所以,他生平最恨情人节,不管是214还是77,他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 ...
随机推荐
- 浅谈Redis及其安装配置
一.Redis的介绍 二.Redis的安装配置 三.Redis的配置文件说明 四.Redis的简单操作 简介: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型. ...
- 【转】蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法--不错
原文网址:http://blog.csdn.net/mzy202/article/details/32408223 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet ...
- eclipse报错 com/genuitec/eclipse/j2eedt/core/J2EEProjectUtil 转
今天eclipse突然报了com/genuitec/eclipse/j2eedt/core/J2EEProjectUtil 错误,并且工程文件打不开了,在网上找了一下资料,然后按照方法操作了一遍,好了 ...
- POJ1218
Problem C Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Total Su ...
- java多线程编程(1) 线程的基本知识
在前面研究过多线程与进程的区别. 这里在稍微总结一下: 进程:程序动态的一次执行过程. 线程:可以只是程序员的一部分的执行过程 每个进程有多个线程组成,在java程序中,至少两个线程一个是垃圾回收线程 ...
- StoryBoard 的使用
简单入门: http://my.oschina.net/plumsoft/blog/53886 详细操作:http://www.cnblogs.com/buro79xxd/archive/2012/0 ...
- 与IO相关的等待事件troubleshooting-系列5
'db file scattered read' 这是另一种常见的等待事件.他产生于Oracle从磁盘读取多个块到Buffer Cache中非连续(" scattered&q ...
- mysql 导出,导入数据
导出 加-d代表只导出表结构 命令行下具体用法如下: mysqldump -u用户名 -p密码 -d 數據库名 表名 脚本名; 1.导出数据库为dbname的表结构(其中用户名为root, ...
- 【设计模式 - 11】之享元模式(FlyWeight)
1 模式简介 当系统中存在大量对象时,非常容易造成内存溢出.为了解决这个问题,我们把这些对象中共有的部分抽象出来,如果有相同的业务请求,则直接返回在内存中已有的对象,避免重新创建,这就是享元 ...
- MFC——error LNK2005: "protected: static struct AFX_MSGMAP
好久没弄VC程序了,今天弄了下,还会用公司给的窗口重绘作为基类来实现,竟然报了这个错误. 找了一下是这里: 有个窗口重绘类是基类: class CBaseDlg : public CDialog 新建 ...