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 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...
随机推荐
- Python-PyQt4学习笔记
1.每个应用必须创建一个 QtGui.QApplication(sys.argv), 此时 QtGui.qApp 为此应用的实例 app = QtGui.QApplication(sys.argv) ...
- Vue基础及脚手架环境搭建
From:http://www.jianshu.com/p/dc5057e7ad0d 一.vue基础 “Vue2.0”跟俺一起全面入坑 01 “Vue2.0”跟俺一起全面入坑 02 “Vue2.0”跟 ...
- vs2017搭建自己的nuget服务器
准备环境 vs2017 第一步 创建一个新的asp.net 空网站 .net框架使用4.6以上版本 (或者在第二部中使用低版本的nuget server) 第二步 打开nuget包管理器 搜索nu ...
- 开源框架AsyncHttpClient使用
开源框架AsyncHttpClient使用 2013-10-14 15:16:35 分类: Android平台 在大神岩岩的推荐下使用了AsyncHttpClient框架,用过之后感觉还是灰常好用滴. ...
- Firefly 3288又一次制作android和lubuntu双系统固件
又一次制作android和lubuntu双系统固件 因为本人改动了lubuntu的驱动和设备树信息,为了方便烧写系统,所以又一次制作了双系统的固件. Firefly wiki教程里有android固件 ...
- scrapy抓取的中文结果乱码解决办法
使用scrapy抓取的结果,中文默认是Unicode,无法显示中文. 中文默认是Unicode,如: \u5317\u4eac\u5927\u5b66 在setting文件中设置: FEED_EXPO ...
- 【JS设计模式】装饰者模式
装饰者模式:在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能.它是通过创建一个包装对象,也就是装饰来包裹真实的对象 装饰模式的特点 (1) 装饰对象和真实对象有同样的接口.这样clien ...
- 655. Big Integer Addition【easy】
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...
- html-文本处理集-持续学习更新
文件处理2:分区分块.有序无序 <!-- 申明HTML5版本 --> <!DOCTYPE html> <html lang="en"> < ...
- Zabbix exp编写
#/usr/bin/python #*-*coding=utf-8*-* import urllib logo = '''\n _____ _ _ _ _____ _ |__ /__ _| |__ | ...