Dreamoon and MRT
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的更多相关文章
- Dreamoon and MRT(二元枚举)
题目 数轴上有M个点a1.a2....am,另有一个数列p1.p2....pn,(1 ≤ pii ≤ M). 给定d1.d2....dn,对所有的 i (1 ≤ i ≤ n),已知 |api+1 - ...
- MODIS批量处理软件MRT的安装说明
最近在处理遥感影像的时候遇见了MODIS影像数据,从中MOD13中提取NDVI是相当的重要.在一番的百度之中找到了处理modis影像的神器------MRT 接下来我来说明一下MRT的具体安装,如果之 ...
- codeforces 477B B. Dreamoon and Sets(构造)
题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 477A A. Dreamoon and Sums(数学)
题目链接: A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- HDR Defered Shading (using MRT)
http://http.download.nvidia.com/developer/SDK/Individual_Samples/DEMOS/Direct3D9/DeferredShading.zip ...
- 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 ...
- cf(#div1 B. Dreamoon and Sets)(数论)
B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
- 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 ...
随机推荐
- struts2通用标签
Struts2框架为我们提供了很多标签,这些标签总体上可以分为两类:通用标签和UI标签.通用标签分为两类:数据标签和控制标签.数据标签用于访问值栈中数据,控制标签用于控制呈现页面时数据执行流程.使用S ...
- 【旧文章搬运】PE重定位表学习手记
原文发表于百度空间,2008-11-02========================================================================== 先定义一下 ...
- caffe 入门实例2 如何写一个模型
占坑,记录如何写一个基于lenet5的模型,并进行测试.
- JAVA基础--JAVA语言组成01
2. 标识符 2.1. 定义: 就是用来起到 标识作用的符号: (就是程序员对自己定义的东西起的名字) 2.2. 命名规则(语法规定的,必须遵守的): 1.可以由大小写字母.数字.下划 ...
- E20180410-hm
preface n. 序言,引语; 开端,前奏; [宗] (弥撒的) 序诵,序祷; vi. 作序; 作为…的序言,作为…的开端; 给…作序; 开始,导致; continue vi. 持 ...
- 51nod 1133【贪心】
思路: 按照终点升序,然后遍历一下就好了: #include <bits/stdc++.h> using namespace std; typedef long long LL; cons ...
- 解决eNSP路由器AR启动失败错误代码40,交换机正常的问题
问题描述 eNSP昨晚正常使用,今天上午出现问题:AR路由器启动失败,错误代码40.但交换机可正常启动. eNSP版本:eNSP V100R002C00B510 Setup.exe 操作系统:Wind ...
- 安装elasticsearch-head
直接安装chrome插件,用npm老出错,shit 再说吧 使用插件连接的时候反而没有出错,后续如果出错 , 可以配置 elasticsearch下config下的y 在新的电脑上使用发现格式不对,比 ...
- iOS NavigationBar 导航栏自定义
1. 设置导航栏NavigationBar的背景颜色: a) setBarTintColor : 设置NagivationBar的颜色 也可以用 : [[UINavigationBar appear ...
- java final static 和final区别
static 和非static 之间的差异,只有当值在运行期间初始化的前提下,这种差异才会揭示出来.因为编译期间的值被编译器认为是相 同的. package thinking; public clas ...