http://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206

原题水题大赛。。

A.珂朵莉的旅行

发现不管非叶子节点选什么,都可以改变叶子节点来满足条件,所以直接算即可

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
using namespace std;
typedef long long ll;
const int N=1e6+7,p=1e9+7;
int n,d[N];
inline int read(){char c;int w;
while(!isdigit(c=getchar()));w=c&15;
while(isdigit(c=getchar()))w=w*10+(c&15);return w;
}
int main(){
n=read();
REP(i,1,n-1){
int x,y;x=read(),y=read();
++d[x];++d[y];
}
ll cnt=1,ans=0;
REP(i,1,n)if(d[i]>1)(cnt<<=1)%=p;
REP(i,1,n)if(d[i]==1)ans+=cnt<<1;else ans+=cnt;
cout<<ans%p<<endl;
return 0;
}

B.奈芙莲的序列

把原序列反过来做LIS

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
using namespace std;
typedef long long ll;
inline int read(){char c,p=0;int w;
while(!isdigit(c=getchar()))if(c=='-')p=1;w=c&15;
while(isdigit(c=getchar()))w=w*10+(c&15);return p?-w:w;
}
inline char smax(int&x,const int&y){return x<y?x=y,1:0;}
inline char smin(int&x,const int&y){return x>y?x=y,1:0;}
const int N=5e5+5;
int n,a[N],b[N],c[N],d[N];
int main(){
n=read();
REP(i,1,n)a[i]=b[i]=read();
sort(b+1,b+1+n);int m=unique(b+1,b+1+n)-b-1;
REP(i,1,n)c[n+i]=c[n-i+1]=lower_bound(b+1,b+1+m,a[i])-b;
int len=1;d[1]=c[1];
REP(i,2,n<<1){
if(c[i]>d[len])d[++len]=c[i];else *lower_bound(d,d+len,c[i])=c[i];
}
cout<<len;
return 0;
}

C.奈芙莲的护符

基础状压DP

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
using namespace std;
typedef long long ll;
inline char smax(int&x,const int&y){return x<y?x=y,1:0;}
inline char smin(int&x,const int&y){return x>y?x=y,1:0;}
int n,k,c[22][22],f[1<<21],g[22][1<<21],L[1<<21];
int main(){
scanf("%d%d",&n,&k);if(n==k)return puts("0"),0;
REP(i,1,n)REP(j,1,n)scanf("%d",&c[i][j]);
REP(t,1,n)REP(i,1,n)REP(j,1,n)smin(c[i][j],c[i][t]+c[t][j]);
const int st=(1<<n)-1;
L[1]=0;
REP(i,2,st)L[i]=L[i>>1]+1;
memset(g,0x3f,sizeof g);
REP(i,1,n){
REP(s,1,st)if((s&(s-1))==0)g[i][s]=c[i][L[s&-s]+1];
else g[i][s]=min(g[i][s&(s-1)],c[i][L[s&-s]+1]);
}
memset(f,0x3f,sizeof f);
int ans=f[0];f[0]=0;
REP(s,0,st){
int cnt=0;
REP(i,1,n)if(s>>i-1&1^1)smin(f[s|(1<<i-1)],f[s]+g[i][st^s^(1<<i-1)]); else ++cnt;
if(cnt==n-k)smin(ans,f[s]);
}
cout<<ans;
return 0;
}

[51Nod]NOIP2018提高组省一冲奖班模测训练(一)题解的更多相关文章

  1. [51Nod]NOIP2018提高组省一冲奖班模测训练(二)

    http://www.51nod.com/contest/problemList.html#!contestId=73&randomCode=4408520896354389006 还是原题大 ...

  2. [51Nod]NOIP2018提高组省一冲奖班模测训练(三) 题解

    链接 A.Anan的派对 题意:Anan想举办一个派对.Anan的朋友总共有 n 人.第i个人如果参加派对会得到 \(c_i\) 的快乐值,除他自己外每多一个人参加他会减少 \(d_i\) 的快乐值. ...

  3. [51Nod]NOIP2018提高组省一冲奖班模测训练(四)翻车记+题解

    链接 下午5点的时候,突然想起来有这个比赛,看看还有一个小时,打算来AK一下,结果因为最近智商越来越低,翻车了,我还是太菜了.上来10分钟先切掉了C和A,结果卡在了B题,唉. A.砍树 一眼题,两遍树 ...

  4. NOIP2018提高组省一冲奖班模测训练(六)

    NOIP2018提高组省一冲奖班模测训练(六) https://www.51nod.com/Contest/ContestDescription.html#!#contestId=80 20分钟AC掉 ...

  5. NOIP2018提高组省一冲奖班模测训练(五)

    NOIP2018提高组省一冲奖班模测训练(五) http://www.51nod.com/Contest/ContestDescription.html#!#contestId=79 今天有点浪…… ...

  6. NOIP2018提高组省一冲奖班模测训练(四)

    NOIP2018提高组省一冲奖班模测训练(四) 这次比赛只AC了第一题,而且花了40多分钟,貌似是A掉第一题里面最晚的 而且还有一个半小时我就放弃了…… 下次即使想不出也要坚持到最后 第二题没思路 第 ...

  7. NOIP2018提高组省一冲奖班模测训练(三)

    NOIP2018提高组省一冲奖班模测训练(三) 自己按照noip的方式考,只在最后一两分钟交了一次 第一题过了,对拍拍到尾. 第二题不会.考试时往组合计数的方向想,推公式,推了一个多小时,大脑爆炸,还 ...

  8. NOIP2018提高组省一冲奖班模测训练(二)

    比赛链接 NOIP2018提高组省一冲奖班模测训练(二) 今天发挥正常,昨天不在状态…… 花了很久A了第一题 第二题打了30分暴力 第三题投机取巧输出test1答案(连暴力都不知道怎么打,太弱了) 2 ...

  9. NOIP2018提高组省一冲奖班模测训练(一)

    比赛链接 https://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206 这次考试的题非常有质量 ...

随机推荐

  1. etTimeout来实现setInterval

    etTimeout来实现setInterval <script type="text/javascript"> function interval(func, w, t ...

  2. 【UVA 437】The Tower of Babylon(拓扑排序+DP,做法)

    [Solution] 接上一篇,在处理有向无环图的最长链问题的时候,可以在做拓扑排序的同时,一边做DP; 设f[i]表示第i个方块作为最上面的最高值; f[y]=max(f[y],f[x]+h[y]) ...

  3. [Python] Pandas load DataFrames

    Create an empty Data frame with date index: import pandas as pd def test_run(): start_date='2017-11- ...

  4. Canvas与Paint的0基础使用

    看了非常多android自己定义方面的资料,了解了非常多原理,遇到人家自己定义的东西也可以看得懂,可是.当自己去自己定义的时候.发现脑袋一片空白,所以就先从认识Canvas和Paint開始吧! Can ...

  5. POJ 3670 Eating Together(LIS)

    Description The cows are so very silly about their dinner partners. They have organized themselves i ...

  6. 记录一下 mysql 的查询中like字段的用法

    SELECT * from t_yymp_auth_role where role_name not like '%测试%' and role_name not like '%部门%' and rol ...

  7. WebAssembly学习(一):认识WebAssembly

    WebAssembly作为一门新兴起的技术,在 JavaScript 圈非常的火!人们都在谈论它多么多么快,怎样怎样改变 Web 开发领域,被各大巨头所推广,这篇文章对其做一个简单的了解认识,本文非原 ...

  8. route---设置Linux内核中的网络路由表

    route命令用来显示并设置Linux内核中的网络路由表,route命令设置的路由主要是静态路由.要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现. 在L ...

  9. 阿里&163 yum源

    站点:https://opsx.alibaba.com/mirror #阿里云base cat /etc/yum.repos.d/alibase.repo [rhel7] name=ali-base ...

  10. Windows上Python2与Python3同时安装、共存

    一.选择 Python2 还是 Python3?当然是全都要 Python3 虽是未来,不过 Python2 的用户群体仍然膨大,网上有大量优良的项目和模块可供使用,遇到问题也基本可以找到解决方法,推 ...