方法太厉害了....看了官方题解的做法....然后...想了很久很久才知道他想表达什么....

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} int T,n;
LL a[],f[][],ans1,ans2;
int d[]; void dfs(int s,LL b, LL sum)
{
if(s==-)
{
if(sum<ans1) ans1=sum,ans2=b;
else if(sum==ans1) ans2=min(ans2,b);
return;
} for(d[s]=;d[s]<=;d[s]++)
{
LL t=sum; t=t+f[s][s];
for(int j=;j>s;j--)
{
if((d[j]+d[s])%==) t=t+f[j][s];
else t=t-f[j][s];
}
dfs(s-,b|(d[s]*(<<s)),t);
}
} int main()
{
scanf("%d",&T); while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
memset(f,,sizeof f); ans1=, ans2=;
for(int i=;i<=n;i++)
{
ans1=ans1+abs(a[i]-a[i-]);
if(a[i]==a[i-]) continue;
int h=-;
for(int j=;j>=;j--)
{
int x1=,x2=;
if(a[i]&(<<j)) x1=; if(a[i-]&(<<j)) x2=;
if(x1==x2) continue; h=j; break;
}
int x=max(a[i],a[i-]),y=min(a[i],a[i-]);
for(int j=h;j>=;j--)
{
int x1=,x2=;
if(x&(<<j)) x1=; if(y&(<<j)) x2=;
f[h][j]=f[h][j]+(x1-x2)*(<<j);
}
}
dfs(,,);
printf("%lld %lld\n",ans2,ans1);
}
return ;
}

HDU 5798 Stabilization的更多相关文章

  1. hdu 1576 A/B(拓展欧几里得)

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. 常用mysql命令

    net start mysql命令,启动mysql数据库 1:查看服务器上存在哪些数据库:show databases;2:建立数据库mydb: create database mydb;3:使用你所 ...

  2. sqlserver 优化相关

    http://www.cnblogs.com/studyzy/archive/2008/11/24/1339772.html http://blog.csdn.net/dba_huangzj/arti ...

  3. Servlet之保存用户偏好设置简单功能的实现

    写在前面: 先来陈述一下为什么会有这样一个需求和这篇博文. 这是公司的一个项目,我们负责前端,后台服务由其他公司负责.该系统有一个系统偏好设置模块,用户可以设置系统的背景图片等系统样式,因为这是一个比 ...

  4. Tsung测试统计报告说明

    Tsung测试统计报告说明 **********************  report.html  *********************** 1.主要统计信息 Tsung统计数据是平均每十秒重 ...

  5. 判断是否点击键盘enter键

    //enter键监测触发事件 function checkKeyCode() { document.onkeydown = function(e) { if(!e) e = window.event; ...

  6. oracle 字段类型详解

    CHAR 固定长度字符串 最大长度2000 bytes VARCHAR2 可变长度的字符串 最大长度4000 bytes 可做索引的最大长度749 NCHAR 根据字符集而定的固定长度字符串 最大长度 ...

  7. python之~利用PIL模块在图片上写写画画

    借鉴了教程: http://yxnt.github.io/2016/05/15/Pillow-Python3.5/ 完成作业如下: 后来学着写给自己的图片加了水印. from PIL import I ...

  8. 淘淘商城_day11_课堂笔记

    今日大纲 发布前的准备 实施发布 一部分是由我来发布 一部分是由你们来发布 讲解分布式部署架构 测试 功能测试 压力测试 项目实战的准备以及分组 分组 抽取功能 讲解所需要开发的功能 项目部署上线流程 ...

  9. 淘淘商城_day05_课堂笔记

    今日大纲 学习Redis 使用Redis完成项目中缓存需求 实现商品详情页功能 缓存的需求 大广告位数据无需每次查询后台系统的接口,可以在前台系统添加缓存,提高访问首页的速度. 商品类目的数据也可以缓 ...

  10. 一个简单的jQuery插件开发实例

    两年前写的一个简单的jQuery插件开发实例,还是可以看看的: <script type="text/javascript" src="jquery-1.7.2.m ...