UVALive 6560 The Urge to Merge
题目链接:传送门
题目大意:有一个 3*n 的矩阵,每个格子里有一个数,你可以选择相邻的两个格子合并成一个,并且权值变为两数乘积,若一个数未合并,权值变为0,求最后权值总和最大值。
题目思路:以 2^3 状态压缩。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 2000005
#define maxn 100005
typedef pair<int,int> PII;
typedef long long LL; int n,m,cnt,ans;
int a[][];
int dp[][];
int deal(int x,int u,int e){
for(int i=;i<;++i)if((u&(<<i))&&(e&(<<i)))return ;
int temp=;
for(int i=;i<;++i){
if(e&(<<i)){
temp+=a[x-][i+]*a[x][i+];
}
}
int t1=,t2=;
e|=u;
if((!(e&))&&(!(e&)))t1=a[x][]*a[x][];
if((!(e&))&&(!(e&)))t2=a[x][]*a[x][];
temp+=max(t1,t2);
return temp;
}
int main(){
int i,j,Case=;
while(scanf("%d",&n)!=EOF&&n){
mst(dp,);
for(i=;i<=;++i)for(j=;j<=n;++j)scanf("%d",&a[j][i]);
for(i=;i<=n;++i){
for(j=;j<=;++j)
for(int k=;k<=;++k){
int temp=deal(i,j,k);
dp[i][j]=max(dp[i][j],dp[i-][k]+temp);
}
}
ans=;
for(i=;i<=;++i) ans=max(ans,dp[n][i]);
printf("Case %d: %d\n",++Case,ans);
}
return ;
}
UVALive 6560 The Urge to Merge的更多相关文章
- UVAlive 6560 - The Urge to Merge(状压dp)
LA 6560 - The Urge to Merge option=com_onlinejudge&Itemid=8&page=show_problem&problem=45 ...
- 状压DP uvalive 6560
// 状压DP uvalive 6560 // 题意:相邻格子之间可以合并,合并后的格子的值是之前两个格子的乘积,没有合并的为0,求最大价值 // 思路: // dp[i][j]:第i行j状态下的值 ...
- 2014 UESTC 暑前集训队内赛(2) 部分解题报告
B.Cuckoo for Hashing 模拟题. 代码: #include <iostream> #include <cstdio> #include <cstring ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 2017西安区域赛A / UVALive - 8512 线段树维护线性基合并
题意:给定\(a[1...n]\),\(Q\)次询问求\(A[L...R]\)的异或组合再或上\(K\)的最大值 本题是2017的西安区域赛A题,了解线性基之后你会发现这根本就是套路题.. 只要用线段 ...
- 逆序数 UVALive 6508 Permutation Graphs
题目传送门 /* 题意:给了两行的数字,相同的数字连线,问中间交点的个数 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 用归并排序或线段树求.想到了就简单了 ...
- 计蒜客 A1607 UVALive 8512 [ACM-ICPC 2017 Asia Xi'an]XOR
ICPC官网题面假的,要下载PDF,点了提交还找不到结果在哪看(我没找到),用VJ交还直接return 0;也能AC 计蒜客题面 这个好 Time limit 3000 ms OS Linux 题目来 ...
- [算法]——归并排序(Merge Sort)
归并排序(Merge Sort)与快速排序思想类似:将待排序数据分成两部分,继续将两个子部分进行递归的归并排序:然后将已经有序的两个子部分进行合并,最终完成排序.其时间复杂度与快速排序均为O(nlog ...
- SQL 提示介绍 hash/merge/concat union
查询提示一直是个很有争议的东西,因为他影响了sql server 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...
随机推荐
- sql getdate()生成单据号
select replace( replace( replace( replace(convert(varchar(23),getdate(),121),'-',''),':',''),' ','') ...
- Linux系统编程之----》信号
"===信号========================================================================================= ...
- C# 中字符串string和字节数组byte[]的转换
string转byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str ); byte[]转string: stri ...
- STM32关总中断的语句
__set_PRIMASK();//关总中断 /************ **********/ __set_PRIMASK();//开总中断
- 对于yum中没有的源的解决办法-EPEL
转载自:http://6260022.blog.51cto.com/6250022/1698352 EPEL 是什么? EPEL (Extra Packages for Enterprise Linu ...
- Groovy小结:java调用Groovy方法并传递参数
Groovy小结:java调用Groovy方法并传递参数 @(JAVA总结) 1. 场景描述 在网上查了资料发现,java有三种方式调用groovy脚本.但是真正在实际的服务器环境中,嵌入groovy ...
- Linux网络流量监控与分析工具Ntopng
Ntopng工具 Ntopng是一个功能强大的流量监控.端口监控.服务监控管理系统 能够实现高效地监控多台服务器网络 Ntopng功能介绍 Ntop提供了命令行界面和web界面两种工作方式,通过web ...
- flink checkpoint 源码分析 (二)
转发请注明原创地址http://www.cnblogs.com/dongxiao-yang/p/8260370.html flink checkpoint 源码分析 (一)一文主要讲述了在JobMan ...
- NiftyNet 项目了解
1. NiftyNet项目概述 NiftyNet项目对tensorflow进行了比较好的封装,实现了一整套的DeepLearning流程.将数据加载.模型加载,网络结构定义等进行了很好的分离,抽象封装 ...
- VMWare虚拟机端口转发
# VMWare虚拟机端口转发 虚拟机和宿主机共用主机IP对外提供服务,又不想提供给虚拟机独立IP,使用VM虚拟机提供的端口转发功能正合适. ### 端口转发--------------------- ...