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

#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. ios 显示其他app的购买页面

    using UnityEngine; using System.Collections; using System.Runtime.InteropServices ; public class IOS ...

  2. C#操作xml文件进行增、删、改

    进行操作的xml文件: products.xml <?xml version="1.0" encoding="utf-8"?><product ...

  3. 二.创建maven工程及下载需要的jar包

    1.使用Eclipse的Maven插件来创建一简单的Maven项目 步骤:打开新建项目对话框,选择Maven Project(File->New->Object->Maven-> ...

  4. 安装aptana(1)

    以前在myeclipse8.5上装了aptana,现在用myeclipse2014了,但是用原来的方法没有安装上,网上搜了下,发现都是老的方法,对新版的myeclipse已经不适用了,下面是转载的一篇 ...

  5. Android内存泄漏检测利器:LeakCanary

    Android内存泄漏检测利器:LeakCanary MAR 28TH, 2016 是什么? 一言以蔽之:LeakCanary是一个傻瓜化并且可视化的内存泄露分析工具 为什么需要LeakCanary? ...

  6. HP Autonomy KeyView入门使用&Maven打包流程

    正文:使用自带的KeyView.jar可能报各种各样的错误,比如no manifest,找不到main方法等等,这里需要自己把需要用到的Filter类和KeyView.jar一起打包,并修改manif ...

  7. Jquery 返回顶部

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  8. 转:详解JMeter正则表达式(1)

    1.概览 JMeter中包含范本匹配软件Apache Jakarta ORO .在Jakarta网站上有一些关于它的文档,例如a summary of the pattern matching cha ...

  9. iis虚拟目录或应用程序不继承父站点的web.config配置信息

    A为主站点 B为A的应用程序站点 再A的web.config中对不想继承的节点用location 套起来.如下: <location path="." allowOverri ...

  10. peepingtom

    简介 辅助评判网页渗透价值的自动化工具.它可以对制定IP和指定端口的所有http(s)服务进行快照,以一种易于浏览阅读的方式展示出来. 安装 git clone https://bitbucket.o ...