题目链接:传送门

题目大意:有一个 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的更多相关文章

  1. UVAlive 6560 - The Urge to Merge(状压dp)

    LA 6560 - The Urge to Merge option=com_onlinejudge&Itemid=8&page=show_problem&problem=45 ...

  2. 状压DP uvalive 6560

    // 状压DP uvalive 6560 // 题意:相邻格子之间可以合并,合并后的格子的值是之前两个格子的乘积,没有合并的为0,求最大价值 // 思路: // dp[i][j]:第i行j状态下的值 ...

  3. 2014 UESTC 暑前集训队内赛(2) 部分解题报告

    B.Cuckoo for Hashing 模拟题. 代码: #include <iostream> #include <cstdio> #include <cstring ...

  4. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  5. 2017西安区域赛A / UVALive - 8512 线段树维护线性基合并

    题意:给定\(a[1...n]\),\(Q\)次询问求\(A[L...R]\)的异或组合再或上\(K\)的最大值 本题是2017的西安区域赛A题,了解线性基之后你会发现这根本就是套路题.. 只要用线段 ...

  6. 逆序数 UVALive 6508 Permutation Graphs

    题目传送门 /* 题意:给了两行的数字,相同的数字连线,问中间交点的个数 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 用归并排序或线段树求.想到了就简单了 ...

  7. 计蒜客 A1607 UVALive 8512 [ACM-ICPC 2017 Asia Xi'an]XOR

    ICPC官网题面假的,要下载PDF,点了提交还找不到结果在哪看(我没找到),用VJ交还直接return 0;也能AC 计蒜客题面 这个好 Time limit 3000 ms OS Linux 题目来 ...

  8. [算法]——归并排序(Merge Sort)

    归并排序(Merge Sort)与快速排序思想类似:将待排序数据分成两部分,继续将两个子部分进行递归的归并排序:然后将已经有序的两个子部分进行合并,最终完成排序.其时间复杂度与快速排序均为O(nlog ...

  9. SQL 提示介绍 hash/merge/concat union

    查询提示一直是个很有争议的东西,因为他影响了sql server 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...

随机推荐

  1. JBoss目录结构说明

    http://www.blogjava.net/livery/articles/262544.html $JBOSS-HOME/bin:             放置各种脚本文件以及相关文件,包括jb ...

  2. adb 修改手机代理方式

    一.使用全局命令 设置代理: adb shell settings put global http_proxy 代理IP地址:端口号 如: adb shell settings put global ...

  3. SQL操作语句之查询及删除重复记录的方法

    delete from 表 where id not in(select min(id) from 表 group by name ) //删除重复名字的记录 删除之前请用语句 select * fr ...

  4. Team Foundation Server安装指南(转载)

    1.说明 Team Foundation Server(以下简称VSTF)的安装并不是一件轻松的事情,在安装的过程中相信很多人都或多或少碰到一些问题而安装不成功,虽然手头有微软提供的所谓安装手册,也曾 ...

  5. centos 中GTK的安装

    centos 中GTK的安装 yum install gtk*

  6. centos7和scientific linux7里面调出中文输入法

    默认安装后,却没有中文输入,于是研究以下,原来是没有调出来. 1.应用程序->系统工具->设置 2.选择“区域和语言” 3.这里默认会有一个汉语,如果没有,那么你当初选择安装的是英语,需要 ...

  7. [svc]msmtp+mutt发附件,发邮件给多个人

    环境:centos6.7 x86-64 内网有web服务器(curl可展示目录) #预安装软件 yum install lrzsz ntpdate sysstat dos2unix wget teln ...

  8. 从头认识Spring-2.3 注解装配-@autowired(3)-通过构造器方法注入

    这一章节我们来讨论一下注解装配的@autowired是如何通过set方法或者其它方法注入? 1.domain 蛋糕类:(不变) package com.raylee.my_new_spring.my_ ...

  9. tensorflow 之模型的保存与加载(一)

    怎样让通过训练的神经网络模型得以复用? 本文先介绍简单的模型保存与加载的方法,后续文章再慢慢深入解读. #!/usr/bin/env python3 #-*- coding:utf-8 -*- ### ...

  10. iOS开发之使用XMPPFramework实现即时通信

    iOS开发之使用XMPPFramework实现即时通信   关于XMPP的理论介绍在本篇博客中就不做赘述了,如何在我们之前的微信中加入XMPP协议来实现通信呢?下面将会介绍一下XMPP的基本的知识,让 ...