Dreamoon and MRT

题目链接:

http://codeforces.com/group/gRkn7bDfsN/contest/212299/problem/B

只需要考虑相对位置,设a0位置为0
枚举
由于对称性,可以设第一步向右,这样总时间减少一半
递归的话省去了cnt部分,直接从O(N2^N-1)变成了O(2^N-1)
可以分析一下几个代码的优化过程

#include <bits/stdc++.h>
using namespace std;
int n, a[], b[], c, cnt, ans = ;
int main() {
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
for (int i = ; i < ( << n); i++) {
int s = ;
c++;
cnt = ;
b[] = s;
for (int j = ; j < n; j++) {
if (i >> j & ) s += a[j];
else s -= a[j];
b[j + ] = s;
}
sort(b, b + n + );
ans = min(ans, (int)(unique(b, b + n + ) - b));
}
printf("%d\n", ans);
}
#include <bits/stdc++.h>
using namespace std;
int n, a[], b[], c, cnt, v[], ans = ;
int main() {
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
for (int i = ; i < ( << n); i++) {
int s = * ;
c++;
cnt = ;
v[s] = c;
for (int j = ; j < n; j++) {
if (i >> j & ) s += a[j];
else s -= a[j];
if (v[s] != c) {
cnt++;
v[s] = c;
}
}
ans=min(ans,cnt);
}
printf("%d\n", ans);
}
#include <bits/stdc++.h>
using namespace std;
int n, a[], b[], c, cnt, v[], ans = ;
int main() {
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
for (int i = ; i < ( << n); i+=) {
int s = * ;
c++;
cnt = ;
v[s] = c;
for (int j = ; j < n; j++) {
if (i >> j & ) s += a[j];
else s -= a[j];
if (v[s] != c) {
cnt++;
v[s] = c;
}
}
ans=min(ans,cnt);
}
printf("%d\n", ans);
}
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 5e6+;
int m,cnt[SIZE],an,d[];
void dfs(int i,int x,int v){
if(i==m){
an=min(an,v);
return;
}
int nxt=x+d[i];
cnt[nxt]++;
dfs(i+,nxt,v+(cnt[nxt]==));
cnt[nxt]--; nxt=x-d[i];
cnt[nxt]++;
dfs(i+,nxt,v+(cnt[nxt]==));
cnt[nxt]--;
}
int main(){
scanf("%d",&m);
an=m+;
for(int i=;i<m;i++)
scanf("%d",&d[i]);
cnt[SIZE/]=;//
cnt[SIZE/+d[]]=;//强制第一步向右
dfs(,SIZE/+d[],);
printf("%d\n",an);
return ;
}

Dreamoon and MRT的更多相关文章

  1. Dreamoon and MRT(二元枚举)

    题目 数轴上有M个点a1.a2....am,另有一个数列p1.p2....pn,(1 ≤ pii ≤ M). 给定d1.d2....dn,对所有的 i (1 ≤ i ≤ n),已知 |api+1 - ...

  2. MODIS批量处理软件MRT的安装说明

    最近在处理遥感影像的时候遇见了MODIS影像数据,从中MOD13中提取NDVI是相当的重要.在一番的百度之中找到了处理modis影像的神器------MRT 接下来我来说明一下MRT的具体安装,如果之 ...

  3. codeforces 477B B. Dreamoon and Sets(构造)

    题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...

  4. codeforces 477A A. Dreamoon and Sums(数学)

    题目链接: A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input ...

  5. HDR Defered Shading (using MRT)

    http://http.download.nvidia.com/developer/SDK/Individual_Samples/DEMOS/Direct3D9/DeferredShading.zip ...

  6. Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学

    C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...

  7. cf(#div1 B. Dreamoon and Sets)(数论)

    B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. cf(#div1 A. Dreamoon and Sums)(数论)

    A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #272 (Div. 1) Problem C. Dreamoon and Strings

    C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. (转)Excel自定义格式详解

    ”G/通用格式”:以常规的数字显示,相当于”分类”列表中的”常规”选项.例:代码:”G/通用格式”.10显示为10:10.1显示为10.1. 2. “#”:数字占位符.只显有意义的零而不显示无意义的零 ...

  2. AJAX --- 一种创建交互式网页应用的网页开发技术

    目录 AJAX 创建XHR实例 指定readyStatechange事件处理程序 启动请求 发送请求 接收数据 取消XHR请求/响应 AJAX ajax核心技术就是 XMLHttpRequest 对象 ...

  3. bzoj 1510 Kra-The Disks —— 思路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1510 一个位置比上面还宽就没用了,而且会收到上面的限制,所以跟上面取 min 即可: 然后维 ...

  4. bzoj3143游走——期望+高斯消元

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3143 只需算出每条边被经过的概率,将概率从小到大排序,从大到小编号,就可得到最小期望: 每条 ...

  5. 如何 Xcode 开发工具里安装一个空的项目末模板

    很多朋友因为Xcode升级取消了空工程模板而发愁  今天给大家推荐一个简单方便的方法,导入空工程模板 对于 xcode7 来说可以使用下面的方法添加空模板.建议在升级的时候,不要下载beta版,最好下 ...

  6. 我的Android笔记(十)—— ProgressDialog的简单应用,等待提示 (转载)

    转自:http://blog.csdn.net/barryhappy/article/details/7376231 在应用中经常会用到一些费时的操作,需要用户进行等待,比如加载网页内容…… 这时候就 ...

  7. angular源码剖析之Provider系列--QProvider

    QProvider 简介 源码里是这么描述的: A service that helps you run functions asynchronously, and use their return ...

  8. 洛谷 - P1443 - 马的遍历 - bfs

    略有收获的bfs,使用了try_enqueue函数使得加入队列非常方便.性能理论上是一样的因为是inline? 还有就是左对齐是使用%-4d,相对于右对齐的%4d,还有右对齐前导零的%04d,自己试一 ...

  9. 算法学习--Day3

    今天搞了一波算法的哈希,代码难道不大,记录在这里吧. 题目描述     “臭味相投”——这是我们描述朋友时喜欢用的词汇.两个人是朋友通常意味着他们存在着许多共同的兴趣.然而作为一个宅男,你发现自己与他 ...

  10. Integer Cache(带你脱坑)

    Integer Cache 废话不多说----->直接上代码: public class IntegerDemo { public static void main(String[] args) ...