当前位置: 首页 > news >正文

Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

传送门

由于n只有15,因此可以枚举每一层是从左走还是从右走,而这一层是一直走到尽头还是走到最后一个再返回取决于上一层,预处理出每一层左右走到尽头的值,再根据枚举出的状态计算即可。总的时间复杂度是O(nn^15)

#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define inf 1000000000LL
#define mod 1000000007
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
char a[20][105];
int c[20][2];
int xu[20];
int main()
{
    //  while(true)
    {
        int n=read(),m=read()+2;
        for(int i=0; i<n; i++) scanf("%s",a[i]);
        int sta=0,flag=0;
        for(int i=0; i<n; i++){
            int p1=-1,p2=-1;
            for(int j=0; j<m; j++){
                if(a[i][j]=='1'){
                    if(p1==-1) p1=j;
                    p2=j;
                }
            }
            if(p1==-1){
                c[i][0]=c[i][1]=0;
                if(!flag) sta++;
            }else{
                flag=1;
                c[i][0]=p2;
                c[i][1]=m-p1-1;
            }
        }
        int cur,pre,sum,ans=inf;xu[n-1]=1;
        for(int i=0; i<(1<<n-sta); i++){
            sum=n-sta-1;
            for(int j=n-2; j>=sta; j--){
                xu[j]=(i>>j-sta)&1;
            }
            for(int j=n-1; j>=sta; j--){
                if(j==sta){
                    sum+=c[j][xu[j]^1];
                }
                else{
                    if(xu[j-1]!=xu[j]) sum+=m-1;
                    else{
                        sum+=2*c[j][xu[j]^1];
                    }
                }
            }
            ans=min(ans,sum);
        }
        if(sta==n) ans=0;
        printf("%d\n",ans);
    }
    return 0;
}

转载于:https://www.cnblogs.com/zsyacm666666/p/6932067.html

相关文章:

  • CloudXNS API PHP SDK V1.0,增加DDNS等特性
  • Firefox 表示不计划开发 Windows 10 手机 APP
  • 没有硬件的 WWDC:苹果欲再造生态圈?
  • mongodb.conf配置文件详解
  • Manjaro Linux 17.0.2 pre 5 发布
  • 微软 PowerShell 成为黑客恶意软件传播工具
  • Docker 收购 Tutum,进一步完善其生态布局
  • 软件工程——团队答辩
  • Scrapy基础(十四)————Scrapy实现知乎模拟登陆
  • IdentityServer4 SigningCredential(RSA 证书加密)
  • 一款基于jQuery Ajax的等待效果
  • uTorrent 被发现悄悄安装挖矿程序,BitTorrent 公司否认
  • TortoiseGit为github账号添加SSH keys,解决pull总是提示输入密码的问题
  • Npcap —— 基于 Winpcap/ Libpcap 的网络包抓取库
  • Lucene 个人领悟 (二)
  • .pyc 想到的一些问题
  • 《Java编程思想》读书笔记-对象导论
  • 【跃迁之路】【699天】程序员高效学习方法论探索系列(实验阶段456-2019.1.19)...
  • 78. Subsets
  • Android Volley源码解析
  • angular学习第一篇-----环境搭建
  • AzureCon上微软宣布了哪些容器相关的重磅消息
  • GDB 调试 Mysql 实战(三)优先队列排序算法中的行记录长度统计是怎么来的(上)...
  • Java,console输出实时的转向GUI textbox
  • nodejs:开发并发布一个nodejs包
  • PHP 小技巧
  • SpiderData 2019年2月25日 DApp数据排行榜
  • vue学习系列(二)vue-cli
  • 阿里云ubuntu14.04 Nginx反向代理Nodejs
  • 安卓应用性能调试和优化经验分享
  • 翻译 | 老司机带你秒懂内存管理 - 第一部(共三部)
  • 给初学者:JavaScript 中数组操作注意点
  • 聚类分析——Kmeans
  • 如何在GitHub上创建个人博客
  • 通过几道题目学习二叉搜索树
  • 通信类
  • 我感觉这是史上最牛的防sql注入方法类
  • 想晋级高级工程师只知道表面是不够的!Git内部原理介绍
  • [Shell 脚本] 备份网站文件至OSS服务(纯shell脚本无sdk) ...
  • Linux权限管理(week1_day5)--技术流ken
  • 阿里云重庆大学大数据训练营落地分享
  • ​【已解决】npm install​卡主不动的情况
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • #### go map 底层结构 ####
  • $emit传递多个参数_PPC和MIPS指令集下二进制代码中函数参数个数的识别方法
  • (1)(1.9) MSP (version 4.2)
  • (2)(2.10) LTM telemetry
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (十)【Jmeter】线程(Threads(Users))之jp@gc - Stepping Thread Group (deprecated)
  • (学习日记)2024.02.29:UCOSIII第二节
  • (转)Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
  • ./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object fil
  • .apk文件,IIS不支持下载解决
  • .bat批处理(十):从路径字符串中截取盘符、文件名、后缀名等信息
  • .net mvc 获取url中controller和action