湖南集训day8

难度:☆☆☆☆☆☆☆



/*
可以先考虑一维,可知 模k意义下相同的前缀和任意两个相减都是k的倍数
问题等价于统计前缀何种模k相同的数的对数。
多维的时候二维前缀和,压行或者压列,n^3可以解决。
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define K 1000007
#define N 400 using namespace std;
typedef long long LL;
int f[K],s[N][N]; int main()
{
freopen("rally.in", "r", stdin);
freopen("rally.out", "w", stdout);
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
scanf("%d",s[i]+j);
s[i][j]+=s[i-][j]+s[i][j-]-s[i-][j-];
if (s[i][j]<) s[i][j]+=k;
if (s[i][j]>) s[i][j]%=k;
}
LL ans=;
f[]=;
for (int l=;l<=m;l++)
for (int r=l;r<=m;r++)
{
for (int i=;i<= n;i++)
{
int sum=s[i][r]-s[i][l-];
if (sum<) sum+=k;
ans+=f[sum];f[sum]++;
}
for (int i=;i<=n;i++)
{
int sum=s[i][r]-s[i][l-];
if (sum<) sum+=k;f[sum]--;
}
}
printf("%lld\n",ans);
return ;
}




/*
树形dp可做,好难好难的样子
考虑贪心 暗点的深度排序,每次拿出未被更新的最深的点把他的k级父亲标记
然后用这个点向外扩展更新每个点距离标记点的距离
正确性显然
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 100007 using namespace std;
int head[N],q[N],f[N],fa[N];
int n,m,ans,cnt,K,t;
struct edge{
int u,v,net;
}e[N<<]; inline int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} inline void add(int u,int v)
{
e[++cnt].v=v;e[cnt].net=head[u];head[u]=cnt;
} void bfs()
{
int he=,ta=;
q[ta++]=;fa[]=;
while(he<=ta)
{
int u=q[he++];;
for(int i=head[u];i;i=e[i].net)
{
int v=e[i].v;
if(!fa[v])
{
fa[v]=u;q[ta++]=v;
}
}
}
} void update(int u)
{
if(!f[u]) return;
for(int i=head[u];i;i=e[i].net)
{
int v=e[i].v;
if(f[v]<f[u]-)
f[v]=f[u]-,update(v);
}
} int main()
{
freopen("general.in", "r", stdin);
freopen("general.out", "w", stdout);
int x,y;
n=read();K=read();t=read();
for(int i=;i<n;i++)
{
x=read();y=read();
add(x,y);add(y,x);
}
bfs();
memset(f,-,sizeof f);
for(int i=n;i;i--)
{
if(f[q[i]]==-)
{
int j=q[i];
for(int k=K;k;k--) j=fa[j];
ans++;f[j]=K;
update(j);
}
}
printf("%d\n",ans);
return ;
}



这道题简直了,妙不可言!!!!!!!!!!!!!!
前方高能题解









可是...那个“比较简单的状压dp”怎么写啊......
gg
std
#include <bits/stdc++.h>
using namespace std; typedef pair<int, int> pii;
#define fir first
#define sec second
#define INF 0x3f3f3f3f
#define MAXN 40005
#define TOP 18 int n, K, m, cnt = 0;
bool a[MAXN];
int dis[18][MAXN], b[70];
pii p[18]; queue <int> q; void bfs(pii st)
{
for (int i = 0; i < MAXN; i++) dis[st.fir][i] = INF;
q.push(st.sec);
dis[st.fir][st.sec] = 0;
while (!q.empty())
{
int x = q.front();
q.pop();
for (int i = 1; i <= m; i++)
{
if (x - b[i] >= 0 && dis[st.fir][x - b[i]] > dis[st.fir][x] + 1)
{
dis[st.fir][x - b[i]] = dis[st.fir][x] + 1;
q.push(x - b[i]);
}
if (x + b[i] <= n && dis[st.fir][x + b[i]] > dis[st.fir][x] + 1)
{
dis[st.fir][x + b[i]] = dis[st.fir][x] + 1;
q.push(x + b[i]);
}
}
}
} int dp[1 << 18]; int solve(int mask)
{
if (dp[mask] != -1) return dp[mask];
if (mask == 0) return 0;
int &ret = dp[mask];
ret = INF;
int x = 0;
while (!(mask & (1 << x))) x++;
for (int i = x + 1; i < 2 * K; i++)
if (mask & (1 << i)) ret = min(ret, solve(mask ^ (1 << x) ^ (1 << i)) + dis[x][p[i].sec]);
return ret;
} int main()
{
freopen("starlit.in", "r", stdin);
freopen("starlit.out", "w", stdout);
scanf("%d %d %d", &n, &K, &m);
for (int i = 1, x; i <= K; i++) scanf("%d", &x), a[x] = true;
for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
for (int i = 0; i <= n; i++) if (a[i] != a[i + 1]) p[cnt] = pii(cnt, i), cnt++;
for (int i = 0; i < cnt; i++) bfs(p[i]);
memset(dp, -1, sizeof dp);
int ans = solve((1 << cnt) - 1);
assert(ans != INF);
printf("%d\n", ans);
return 0;
}
湖南集训day8的更多相关文章
- 主席树 || 可持久化线段树 || BZOJ 3653: 谈笑风生 || Luogu P3899 [湖南集训]谈笑风生
		
题面:P3899 [湖南集训]谈笑风生 题解: 我很喜欢这道题. 因为A是给定的,所以实质是求二元组的个数.我们以A(即给定的P)作为基点寻找答案,那么情况分两类.一种是B为A的父亲,另一种是A为B的 ...
 - P3900 [湖南集训]图样图森破
		
P3900 [湖南集训]图样图森破 链接 分析: 感觉像个暴力. 可以枚举回文串的回文中心,即枚举一个串,枚举一个串的位置作为回文中心,然后求出这个串内的回文串的长度. 此时如果回文串两端都没有到这个 ...
 - [日常训练]常州集训day8
		
T1 Description 给定一个长度为$n$的正整数序列$a$.可以将序列分成若干段,定义第$i$段的权值$x_i$为这一段中所有数的最大值,特殊地,$x_0=0$.求$\sum_{i=1}^{ ...
 - bzoj 3653 [湖南集训]谈笑风生
		
题目描述 设 T 为一棵有根树,我们做如下的定义: • 设 a 和 b 为 T 中的两个不同节点.如果 a 是 b 的祖先,那么称"a 比 b 不知道高明到哪里去了". • 设 a ...
 - luogu P3899 [湖南集训]谈笑风生
		
传送门 nmyzd,mgdhls,bnmbzdgdnlql,a,wgttxfs 对于一个点\(a\),点\(b\)只有可能是他的祖先或者在\(a\)子树里 如果点\(b\)是\(a\)祖先,那么答案为 ...
 - 洛谷P3899 [湖南集训]谈笑风生(线段树合并)
		
题意 题目链接 Sol 线段树合并板子题,目前我看到两种写法,分别是这样的. 前一种每次需要新建一个节点,空间是\(O(4nlogn)\) 后者不需要新建,空间是\(O(nlogn)\)(面向数据算空 ...
 - P3899 [湖南集训]谈笑风生
		
题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=3653 https://www.luogu.org/problemnew/show/P38 ...
 - LG3898 [湖南集训]大新闻
		
题意 题目描述 **记者弄了个大新闻,这个新闻是一个在 [0,n) 内等概率随机选择的整数,记其为 x.为了尽可能消除这个大新闻对公众造成的不良印象,我们需要在 [0,n)内找到某一个整数 y,使得 ...
 - 【洛谷 P3899】 [湖南集训]谈笑风生 (主席树)
		
题目链接 容易发现\(a,b,c\)肯定是在一条直链上的. 定义\(size(u)\)表示以\(u\)为根的子树大小(不包括\(u\)) 分两种情况, 1.\(b\)是\(a\)的祖先,对答案的贡献是 ...
 
随机推荐
- KMP瞎扯一下
			
什么是KMP KMP俗称看毛片算法,是高效寻找匹配字串的一个算法 百度百科 KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现,因此人们称它为 ...
 - MySql-了解存储引擎
			
怎么应对不同版本 在不同的 mysql 版本中,很多特性和语法有可能是不一样的,我们怎么样才能知道当前版本的语法是什么样呢?最好的办法是学会使用 mysql 的帮助. A.按照层次看帮助 例如:mys ...
 - linux time-统计给定命令所花费的总时间
			
推荐:更多linux 性能监测与优化 关注:linux命令大全 time命令用于统计给定命令所花费的总时间. 语法 time(参数) 参数 指令:指定需要运行的额指令及其参数. 实例 当测试一个程序或 ...
 - Journals in Fluid Mechanics
			
journal of fluid mechanics physics of fluids annual review of fluid mechanics
 - MySQL Connector/Python 接口 (二)
			
连接数据库 本文参见这里,示例如何连接MySQL 数据库. import mysql.connector from mysql.connector import errorcode # 连接数据库需要 ...
 - i2c中start和restart的区别
			
有的硬件芯片提供了一个个寄存器,供我们很好的操作i2c,但是,在用的时候,我们是不知道他到地是怎么操作的,下边,我就探讨下i2c中的start和restart的区别. start是在scl是高电平的时 ...
 - 【瞎扯】 About Me
			
手动博客搬家: 本文发表于20181218 13:54:31, 原地址https://blog.csdn.net/suncongbo/article/details/85063885 来了?坐,欢迎来 ...
 - RequestMapping_Ant 路径
			
[使用@RequestMapping映射请求] [Ant风格资源地址支持3种匹配符] (1)? :匹配文件名中的一个字符. (2) * :匹配文件名中的任意字符. (3) ** :**匹配多层路径. ...
 - 《Spring Boot 那些事》
			
<Spring Boot 那些事>----https://www.bysocket.com/?p=1124
 - [C++] 自己主动关闭右下角弹窗
			
近期腾讯.迅雷等各种client,都越发喜欢在屏幕的右下角弹框了. 有骨气的人当然能够把这些软件卸载了事,可是这些client在某些情况下却又还是实用的.怎么办呢? 作为码农,自己实现一个自己主动关闭 ...