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 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...
随机推荐
- !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)
题意:有一个n*n的格子.每一个格子里有不同数量的食物,老鼠从(0,0)開始走.每次下一步仅仅能走到比当前格子食物多的格子.有水平和垂直四个方向,每一步最多走k格,求老鼠能吃到的最多的食物. 分析: ...
- zabbix触发的多条件判断表达式
2 Trigger expression Overview The expressions used in triggers are very flexible. You can use them ...
- java.lang.NullPointerException org.apache.jsp.index_jsp._jspInit(index_jsp.java:22)
java.lang.NullPointerException org.apache.jsp.index_jsp._jspInit(index_jsp.java:22) org.apache.jsp.i ...
- flashback database(drop tablespace)
1.首先记录时间 select to_char(systimestamp,'yyyy-mm-dd HH24:MI:SS') from dual;--2014-04-25 13:55:48 查看表sel ...
- 关于数组中加入相同的view的试验
随便新建一个工程,然后在控制器中粘贴如下代码 - (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]ini ...
- CentOS源码编译安装Nginx
安装编译用到的软件: yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel 现在到http://nginx.o ...
- memcahced&redis命令行cmd下的操作
一.memcahced 1.安装 执行memcached.exe -d install 把memcached加入到服务中 执行memcached.exe -d uninstall 卸载memcac ...
- Atitit php序列化 php的serialize序列化和json序列化
Atitit php序列化 php的serialize序列化和json序列化 PHP 对不同类型的数据用不同的字母进行标示,Yahoo 开发网站提供的Using Serialized PHP with ...
- OSGi规范概要
目前最新的OSGi规范是2012年7月发布的Release 5,Version5.0(后文简称为R5.0)版本,该规范定义了Java模块化系统所涉及的各种场景(开发.打包.部署.更新和交互等),以及其 ...
- 奇怪的string
代码1: #include <iostream> //#include <string> using namespace std; int main(int argc, cha ...