FZU 2060 The Sum of Sub-matrices(状态压缩DP)
The Sum of Sub-matrices
Description
Seen draw a big 3*n matrix , whose entries Ai,j are all integer numbers ( 1 <= i <= 3, 1 <= j <= n ). Now he selects k sub-matrices( each Aij only belong one sub-matrices ), hoping to find the largest sum of sub-matrices’ elements.
Input
There are multiple test cases.
For each test case, the first line contains an integer n, k (1 <= n <= 100, 1 <= k <= 5, 3 * n >= k). The next three lines with n integers each gives the elements of the matrix ( | Ai,j | <= 10000).
Output
Sample Input
Sample Output
求3*n的矩阵里面的 k个子矩阵的最大和。
对列进行状态压缩
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm> using namespace std; typedef long long LL;
typedef pair<int,int> pii;
const int mod = 1e9+;
const int N = ;
const int M = ;
#define X first
#define Y second int st1[M] = { , , , , , , , , , , , , };
int st2[M] = { , , , , , , , , , , , , };
int num[M] = { , , , , , , , , , , , , };
int A[][N] , dp[N][][M] , n , k ; int Sum( int colum , int st ) {
int res = ;
for( int i = ; i < ; ++i ) if( st&(<<i) )res += A[i][colum];
return res ;
} void Run() {
memset( dp , 0x80 , sizeof dp ) ;
dp[][][] = ; for( int i = ; i < ; ++i )
for( int j = ; j <= n ; ++j )
cin >> A[i][j]; for( int i = ; i <= n ; ++i ) {
for( int cs = ; cs < M ; ++cs ) {
for( int ps = ; ps < M ; ++ps ) {
int w = Sum(i,st2[cs]);
for( int k1 = ; k1 <= k ; ++k1 ) {
int low = num[cs] , up = num[cs] ;
for( int z = ; z < ; ++z ) if( st1[cs] & st1[ps] &(<<z) ) low--;
for( int k2 = low ; k1 + k2 <= k && k2 <= up ; ++k2 ){
dp[i][k1+k2][cs] = max( dp[i][k1+k2][cs] , dp[i-][k1][ps] + w );
}
}
}
}
}
cout << *max_element( dp[n][k] , dp[n][k]+M ) << endl ;
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
while( cin >> n >> k )Run();
}
FZU 2060 The Sum of Sub-matrices(状态压缩DP)的更多相关文章
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- hdu 4057(ac自动机+状态压缩dp)
题意:容易理解... 分析:题目中给的模式串的个数最多为10个,于是想到用状态压缩dp来做,它的状态范围为1-2^9,所以最大为2^10-1,那我们可以用:dp[i][j][k]表示长度为i,在tri ...
- HDU1565+状态压缩dp
简单的压缩状态 dp /* 状态压缩dp 同hdu2167 利用滚动数组!! */ #include<stdio.h> #include<string.h> #include& ...
- POJ1185 - 炮兵阵地(状态压缩DP)
题目大意 中文的..直接搬过来... 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平 ...
- HDU2167+状态压缩DP
状态压缩dp 详见代码 /* 状态压缩dp dp[ i ][ j ]:第i行j状态的最大和 dp[i][j] = max( dp[i-1][k]+sum[i][j] ); 题意:给定一个N*N的方格, ...
- POJ 3254 Corn Fields (状态压缩DP)
题意:在由方格组成的矩形里面种草,相邻方格不能都种草,有障碍的地方不能种草,问有多少种种草方案(不种也算一种方案). 分析:方格边长范围只有12,用状态压缩dp好解决. 预处理:每一行的障碍用一个状态 ...
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
随机推荐
- BUUCTF--reverse3
测试文件:https://buuoj.cn/files/aa4f6c7e8d5171d520b95420ee570e79/a9d22a0e-928d-4bb4-8525-e38c9481469e.ra ...
- 【JAVA】 04-Java中的多线程
链接: 笔记目录:毕向东Java基础视频教程-笔记 GitHub库:JavaBXD33 目录: <> <> 内容待整理: 多线程引入 概述 多线程: 进程:正在执行中的程序,其 ...
- 【JAVA】 01-Java基础知识
链接: 笔记目录:毕向东Java基础视频教程-笔记 GitHub库:JavaBXD33 测试 01-Java基础知识 一.数据类型 基本类型 包装类型 缓存池 二.String 概览 不可变的好处 S ...
- ASE Alpha Sprint - backend scrum 6
本次scrum于2019.11.11在sky garden进行,持续30分钟. 参与人: Zhikai Chen, Jia Ning, Hao Wang 请假: Xin Kang, Lihao Ran ...
- sd卡无法启动及zc706更改主频后可以进入uboot无法启动kernel的坑
好长的标题 +_+ 1.sd卡无法启动 起因:kernel底下通过dd测试速度,擦写了sd卡,再启动时发现无法启动 于是重新格式化,再将BOOT.bin 相关dtb u-rootfs zImage和u ...
- Flutter-RaisedButton
RaisedButton({ Key key, //点击按钮的回调出发事件 @required VoidCallback onPressed, //水波纹高亮变化回调 ValueChanged< ...
- centos 6.5 切换用户
root --> user,无需密码 su username user --> root,需要 root 密码 su root root 可省略
- vue项目放在IE上页面空白的问题
Babel是一个广泛使用的转码器,可以将ES6代码转为ES5代码 1.npm install babel-polyfill --save 2.main.js中引入 import 'babel-poly ...
- js-放大镜效果
jd或者淘宝的具体商品有个放大镜的效果.虽然网上类似插件琳琅满目,应用到项目上有诸多不便,自己抽点时间自己写了个类似插件,积累下代码,何乐而不为呢!!let‘go: 打算把此特效封装成个插件,先把最基 ...
- 接口代码(requests库安装)
一. 首先用cd:Scripts路径名命令,进入到python--Scripts目录下:然后键入pip install requests 进行安装,有可能会要求你升级pip,键入python -m ...