2017-10-5 清北刷题冲刺班p.m
套路(拓扑排序)

/*
对每个联通块单独考虑。
每个联通块是一个环套树,树边拎出来可以随意定向,记树边为 m,所以树的方案数为2^m 。
对于环来说只有两种方向,顺时针和逆时针,记环边为 n,所以环的方案就是 2^n - 2。
最后把每个联通块的方案乘起来即可。
注意,自环无论如何定向都是环,但这并不违反环的公式,故可以不特判。
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 200010
#define mod 1000000007
int con[maxn],deg[maxn],seq[maxn];
int n,m;
long long ans;
long long Pow(long long a,long long b){
long long res=;
while(b){
if(b&)res=res*a%mod;
a=a*a%mod;
b>>=;
}
return res;
}
void dfs(int x){
m++;
deg[x]=;
if(deg[con[x]])dfs(con[x]);
}
int main(){
freopen("road.in","r",stdin);freopen("road.out","w",stdout);
//freopen("Cola.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&con[i]);
deg[con[i]]++;
}
int h=,t=;
for(int i=;i<=n;i++){
if(!deg[i])seq[++t]=i;
}
while(h<=t){
int to=con[seq[h]];
deg[to]--;
if(!deg[to])seq[++t]=to;
++h;
}
ans=Pow(,t);
for(int i=;i<=n;i++){
if(deg[i]){
m=;
dfs(i);
ans=(ans*(Pow(,m)-))%mod;
}
}
ans=(ans+mod)%mod;
cout<<ans;
}
100分 拓扑排序
exLCS(动态规划)


#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
#define INF 0x7fffffff
using namespace std;
char a[],b[maxn];
int f[][],nxt[maxn][];
int n,m;
void solve(){
f[][]=nxt[][a[]-'a'];
for(int i=;i<=n;i++)f[i][]=-;
for(int i=;i<n-;i++)
for(int j=;j<=n&&f[i][j]<INF;j++){
f[i+][j]=min(f[i+][j],f[i][j]);
if(j<n)f[i+][j+]=min(f[i+][j+],nxt[f[i][j]+][a[i+]-'a']);
}
}
int main(){
freopen("lcs.in","r",stdin);freopen("lcs.out","w",stdout);
scanf("%s%s",a,b);
n=strlen(a);m=strlen(b);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
f[i][j]=INF;
for(int i=;i<;i++)nxt[m][i]=INF;
for(int i=m-;i>=;i--){
memcpy(nxt[i],nxt[i+],sizeof(nxt[i]));
nxt[i][b[i]-'a']=i;
}
solve();
int ans=;
for(int i=n;i;i--)
if(f[n-][i]<INF){
ans=i;
break;
}
cout<<ans;
}
100分 dp
魔方(模拟)


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> int c[],n,flag=false,out[],ans; inline void read(int &now)
{
char Cget;now=;while((Cget=getchar())<''&&Cget>'');
while(Cget>=''&&Cget<='')now=now*+Cget-'',Cget=getchar();
} void operation_A()
{
int tmp,tmp2;
tmp=c[];
c[]=c[],c[]=c[],c[]=c[],c[]=tmp;
tmp=c[],tmp2=c[];
c[]=c[],c[]=c[],c[]=c[],c[]=c[];
c[]=c[],c[]=c[],c[]=tmp2,c[]=tmp;
} void operation_B()
{
int tmp,tmp2;
tmp=c[];
c[]=c[],c[]=c[],c[]=c[],c[]=tmp;
tmp=c[],tmp2=c[];
c[]=c[],c[]=c[],c[]=c[],c[]=c[];
c[]=c[],c[]=c[],c[]=tmp2,c[]=tmp;
} void operation_C()
{
int tmp=c[],tmp2;
c[]=c[],c[]=c[],c[]=c[],c[]=tmp;
tmp=c[],tmp2=c[];
c[]=c[],c[]=c[],c[]=c[],c[]=c[];
c[]=c[],c[]=c[],c[]=tmp,c[]=tmp2;
} bool check()
{
return c[]==c[]&&c[]==c[]&&c[]==c[]&&
c[]==c[]&&c[]==c[]&&c[]==c[]&&
c[]==c[]&&c[]==c[]&&c[]==c[]&&
c[]==c[]&&c[]==c[]&&c[]==c[]&&
c[]==c[]&&c[]==c[]&&c[]==c[]&&
c[]==c[]&&c[]==c[]&&c[]==c[];
} void dfs(int now,int last)
{
if(check())
{
flag=true,ans=now;
return;
}
if(now>=n) return;
if(last!=)
{
for(int i=;i<=;i++)
{
operation_A();
out[now+]=i;
dfs(now+,);
if(flag) return;
}
operation_A();
}
if(last!=)
{
for(int i=;i<=;i++)
{
operation_B();
out[now+]=+i;
dfs(now+,);
if(flag) return;
}
operation_B();
}
if(last!=)
{
for(int i=;i<=;i++)
{
operation_C();
out[now+]=+i;
dfs(now+,);
if(flag) return;
}
operation_C();
}
} void dfs2(int now,int last)
{
if(check())
{
flag=true,ans=now;
return;
}
if(now>=n) return;
if(last!=)
{
for(int i=;i<=;i++)
{
operation_A();
out[now+]=i;
dfs(now+,);
if(flag) return;
}
operation_A();
}
if(last!=)
{
for(int i=;i<=;i++)
{
operation_B();
out[now+]=+i;
dfs(now+,);
if(flag) return;
}
operation_B();
}
} int main()
{
freopen("cube.in","r",stdin);
freopen("cube.out","w",stdout);
read(n);
for(int i=;i<=;i++) read(c[i]);
if(n<=)
{
dfs(,);
for(int i=;i<=ans;i++) printf("%d ",out[i]);
}
else
{
if(n<=) dfs2(,);
if(!flag) dfs(,);
for(int i=;i<=ans;i++) printf("%d ",out[i]);
}
fclose(stdin),fclose(stdout);
return ;
}
100分 模拟
2017-10-5 清北刷题冲刺班p.m的更多相关文章
- 2017-10-4 清北刷题冲刺班p.m
P102zhx a [问题描述]你是能看到第一题的 friends 呢.——hja两种操作:1.加入一个数.2.询问有多少个数是?的倍数.[输入格式]第一行一个整数?,代表操作数量.接下来?行,每行两 ...
- 2017-10-4 清北刷题冲刺班a.m
P101zhx a [问题描述]你是能看到第一题的 friends 呢.——hjaHja 拥有一套时光穿梭技术,能把字符串以超越光速的速度传播,但是唯一的问题是可能会 GG.在传输的过程中,可能有四种 ...
- 2017-10-3 清北刷题冲刺班p.m
a [问题描述]你是能看到第一题的 friends 呢.——hja给你一个只有小括号和中括号和大括号的括号序列,问该序列是否合法.[输入格式]一行一个括号序列.[输出格式]如果合法,输出 OK,否则输 ...
- 2017-10-3 清北刷题冲刺班a.m
P99zhx a [问题描述]你是能看到第一题的 friends 呢.——hja怎么快速记单词呢?也许把单词分类再记单词是个不错的选择.何大爷给出了一种分单词的方法,何大爷认为两个单词是同一类的当这两 ...
- 2017-10-2 清北刷题冲刺班a.m
一道图论神题 (god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只 ...
- 2017-10-2 清北刷题冲刺班p.m
最大值 (max) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一本书,上面有很多有趣的OI问题.今天LYK看到了这么一道题目: 这里有一个长度为n ...
- 2017-10-1 清北刷题冲刺班p.m
一道图论好题 (graph) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图 ...
- 2017-10-7 清北刷题冲刺班p.m
测试 A 同花顺 文件名 输入文件 输出文件 时间限制 空间限制card.cpp/c/pas card.in card.out 1s 512MB题目描述所谓同花顺,就是指一些扑克牌,它们花色相同,并且 ...
- 2017-10-7 清北刷题冲刺班a.m
测试 A 消失的数字 文件名 输入文件 输出文件 时间限制 空间限制del.cpp/c/pas del.in del.out 1s 512MB题目描述现在,我的手上有 n 个数字,分别是 a 1 ,a ...
- 2017-10-1 清北刷题冲刺班a.m
位运算1 (bit) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK拥有一个十进制的数N.它赋予了N一个新的意义:将N每一位都拆开来后再加起来就是N所拥 ...
随机推荐
- g++能过,c++过不了
可能原因: 1.在递归的时候,递归函数中忘记加返回return.(详见Wrong Answer,Memory Limit Exceeded) 代码1:错误 g++--------accepted c+ ...
- 分析CSS布局中BFC
1.什么是BFC BFC(Block Formatting Context,块级元素格式化上下文)是 W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关系和 ...
- Linux-解决putty无法直接使用root用户远程登录linux主机的问题
问题描述: 有时,在使用putty连接远程linux主机时会发现,无法直接使用root登录, 但是可以使用其他用户登录,然后切换至root用户. 解决办法: 1.修改配置文件 vi /etc/ssh/ ...
- linux命令学习笔记(9):touch 命令
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. .命令格式: touch [选项]... 文件... .命令参数: -a 或--t ...
- ffpanel --ffmpeg的GUI,让ffmpeg离开黑黑的命令行
程序及源码下载地址 :https://github.com/langsim/ffpanel from:http://blog.csdn.net/langsim/article/details/47 ...
- poj2395
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> ...
- ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...
- html之ajax
正常情况下,html中的ajax(也就是XMLHttpRequest对象)是不能跨域的.(特殊情况,此处不讨论,请网上Google) ---跨域:是url的协议或ip或端口,其中有一个不同,就是跨域. ...
- bzoj 2039 & 洛谷 P1791 人员雇佣 —— 二元关系最小割
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2039 https://www.luogu.org/problemnew/show/P1791 ...
- linux下mysql配置查询
1.查看mysql的数据文件存放位置 show variables; 显示结果中的: datadir的值即是. 2.查看mysql是否支持表分区 SHOW VARIABLES LIKE '%parti ...