首页 > 其他分享 >【比赛】8.16

【比赛】8.16

时间:2023-08-16 14:57:06浏览次数:68  
标签:8.16 比赛 int id2 id1 ch now dis

Ⅰ.LYK loves string


通过限定元素的先后可以将 \(10^10\) 优化成 \(10!\) ,再加一些剪枝就可以过了。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int read(){
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -f; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
	return x * f; 
} 
int n, m, k, ans;
int f[15], g[15];
map<string, int> H;
void dfs(int fl, int sum, int tot, string now){
	if(sum > m || tot > k || g[n - fl + 1] + sum < m) return ;
	if(fl > n){
		if(sum != m) return ;
		ans = (ans + f[tot]) % mod;
		return ;
	}
	for(int i = tot + 1; i; --i){
		char y = i + 'a' - 1;
		string x = ""; x += y;
		int t = 0;
		if(!H[x]) ++t;
		++H[x];
		if(now.size()){
			for(int j = now.size() - 1; j >= 0; --j){
				x = now[j] + x;
				if(!H[x]) ++t;
				++H[x];
 			}
		} 
		string pre = now;
		x.clear();
		x += y;
		now += x;
		dfs(fl + 1, sum + t, tot + (i == tot + 1), now);
		now = pre;
		--H[x];
		if(now.size()){
			for(int j = now.size() - 1; j >= 0; --j){
				x = now[j] + x;
				--H[x];
 			}
		} 
	} 
}
signed main(){
//	freopen("string.in", "r", stdin);
//	freopen("string.out", "w", stdout);
	n = read(), m = read(), k = read();
	int x = k - 1; f[1] = k;
	for(int i = 2; i <= min(n, k); ++i) f[i] = f[i - 1] * x % mod, x --;
	x = n - 1; g[1] = n;
	for(int i = 2; i <= n; ++i) g[i] = g[i - 1] + x, x --;
	dfs(1, 0, 0, "");
	printf("%lld\n", ans);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
} 

Ⅱ.LYK loves graph

分层图最短路,因为有些连通块不能一笔画,会漏解。所以有些情况往回走可以不加代价。具体看代码。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e2 + 67;
int read(){
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -f; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
	return x * f; 
} 
int n, m, k, ans = 0x3f3f3f3f3f3f3f3f;
int c[N][N], a[N][N], dis[N * N * 7];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int id(int i, int j, int floor){
	return (i - 1) * m + j + (floor - 1) * n * m;
}
struct node{
	int dis, x, y, k;
	bool operator < (const node &A) const{return dis > A.dis;}
};
bitset<300> col[N * N * 7], mp[N * N * 7];
priority_queue<node> pq;
bool vis[N * N * 7];
bool check(int x, int y){
	if(x < 1 || x > n || y < 1 || y > m) return false;
	return true;
}
void solve(int sx, int sy, int sk){
	while(!pq.empty()) pq.pop();
	memset(dis, 0x3f, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	for(int i = 1; i <= n * m * k; ++i) col[id(sx, sy, sk)].reset(), mp[id(sx, sy, sk)].reset();
	dis[id(sx, sy, sk)] = a[sx][sy];
	pq.push((node){a[sx][sy], sx, sy, sk});
	col[id(sx, sy, sk)][c[sx][sy]] = 1;
	mp[id(sx, sy, sk)][id(sx, sy, 1)] = 1;
	while(!pq.empty()){
		node now = pq.top(); pq.pop();
		int id1 = id(now.x, now.y, now.k), id2;
		if(vis[id1]) continue;
		vis[id1] = 1;
		if(now.k == k){
			ans = min(ans, dis[id1]);
			continue;
		}
		for(int i = 0; i < 4; ++i){
			int x = now.x + dx[i];
			int y = now.y + dy[i];
			if(!check(x, y) || c[x][y] == -1) continue;
			if(col[id1][c[x][y]]){
				id2 = id(x, y, now.k);
				if(dis[id2] > dis[id1] + a[x][y]){
					if(mp[id1][id(x, y, 1)]) dis[id2] = dis[id1];
					else dis[id2] = dis[id1] + a[x][y];
					col[id2] = col[id1];
					mp[id2] = mp[id1]; mp[id2][id(x, y, 1)] = 1;
					pq.push((node){dis[id2], x, y, now.k});
				}
			}else{
				id2 = id(x, y, now.k + 1);
				if(dis[id2] > dis[id1] + a[x][y]){
					dis[id2] = dis[id1] + a[x][y];
					col[id2] = col[id1]; col[id2][c[x][y]] = 1;
					mp[id2] = mp[id1]; mp[id2][id(x, y, 1)] = 1;
					pq.push((node){dis[id2], x, y, now.k + 1});
				}
			}
		}
	}
}
signed main(){
//	freopen("graph.in", "r", stdin);
//	freopen("graph.out", "w", stdout);
	n = read(), m = read(), k = read();
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			c[i][j] = read();
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			a[i][j] = read();
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			if(c[i][j] != -1) solve(i, j, 1);
	printf("%lld\n", ans);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
} 

Ⅲ.LYK loves rabbits


标签:8.16,比赛,int,id2,id1,ch,now,dis
From: https://www.cnblogs.com/jiangchen4122/p/17634857.html

相关文章

  • 8.16集训笔记
    上午/一维数组排序排序:sort,冒泡,选择,插入,计数复杂度:\(O(nlogn),O(n^2),O(n^2),O(n^2),O(n)\)点击查看代码#include<bits/stdc++.h>#include<algorithm>usingnamespacestd;constintN=1e5+10;inta[N],n;intmain(){//cin>>n;//for(inti=1;i<=n;......
  • 2023.8.16
    今天不是生日,也没有节日,普通得不能再普通的一天。无聊随意翻网站,偶然翻到了两年前生日发的博客,不知道为何内心有点波澜,想写点东西,但也不知道写什么。回忆我回忆起了2021年3月14日,我正坐在图书馆三楼(可能是)我一个很少光顾的位置上,午后阳光很懒,慢慢撒到桌子上,映红半张草稿纸,我在费......
  • 【比赛】8.14
    Ⅰ.妹子第一题考虑被包含的矩阵需不需要旋转,如上图,我们可以枚举\(x\)来判断是否可行。#include<bits/stdc++.h>#definedbdouble#defineeqs1e-6usingnamespacestd;intread(){ intx=0,f=1;charch=getchar(); while(ch<'0'||ch>'9'){if(ch==......
  • 某谷 Rated 比赛泛做
    P9535「YsOI2023」连通图计数非常好题目,爱来自湖南。\(m=n-1\)等价于给定度数求树的个数,这是一个经典题,在「HNOI2004」树的计数有描述,即利用Prufer序列得到答案为\(\binom{n-2}{(d_1-1)(d_2-1)\ldots(d_n-1)}\)。\(m=n\)即基环树,对于整个大环建立一个虚点,该点向环上的所......
  • 【比赛】8.13
    Ⅰ.波状数列考试时想到的是用\(f_{i,0/1}\)表示用了前\(i\)个数,其中第一个数是山峰还是山谷。比较麻烦。之前看题解做的时候,用\(f_{i,j}\)表示用了前\(i\)个数,其中第一个数是\(j\),滚动数组优化一下。点击查看代码#include<bits/stdc++.h>#defineintlonglongc......
  • 20230810比赛
    T1队列变换DescriptionFJ打算带他的N(1<=N<=30,000)头奶牛去参加一年一度的“全美农场主大奖赛”。在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席前依次走过。今年,竞赛委员会在接受队伍报名时,采用了一种新的登记规则:他们把所有队伍中奶牛名字的首字......
  • 人工智能/数据科学比赛汇总 2019.9
    Github:iphysresearch/DataSciComp本项目由ApacheCN强力支持。微博|知乎|简书|全球数据智能大赛(2019)——“数字人体”赛场一:肺部CT多病种智能诊断https://tianchi.aliyun.com/competition/entrance/231724/6月24-9月09,2019//Hostby天池//Prize:$900,000Note:......
  • 射击比赛
    1.题目给定一个射击比赛成绩单包含多个选手若干次射击的成绩分数请对每个选手按其最高三个分数之和进行降序排名输出降序排名后的选手ID序列条件如下:一个选手可以有多个射击成绩的分数且次序不固定如果一个选手成绩小于三个则认为选手的所有成绩无效排名忽略该选手......
  • 【比赛·总结】2023.8 学而思Z6模拟赛
    2023.8学而思Z6模拟赛考试界面:(隐藏)题解反思在本次考试中,作者惨遭爆零。警钟长鸣\(3\)分钟。作者认为,爆零的主要原因在于作者并没有遵从“遇到难题则跳过”的原则,疯狂卡在第一题上,从第\(0\)分钟一直到最后\(1\)秒,除了其中写了一个第二题的暴力,还因为读错题没得分以外,其......
  • 篮球比赛现场信息管理实时展示系统-开发随笔1
    关键字:篮球比赛排球比赛足球比赛 比赛管理训练管理训练数据采集实时展示比赛报分比分展示LED大屏场馆大屏[当前现状]体育场馆内的LED显示屏作为广告、比赛信息显示和比赛实况播放最重要的载体之一,已成为现代化体育场馆的必备设施。各类体育赛事通过显示屏传达给更多......