提交记录 15662


用户 题目 状态 得分 用时 内存 语言 代码长度
TOE noip17e. 【NOIP2017】宝藏 Accepted 100 45.718 ms 33740 KB C++ 1.31 KB
提交时间 评测时间
2021-01-22 10:48:40 2021-01-22 10:48:45
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,m,bn,a[20][20],g[1<<12][1<<12],c[1<<12][1<<12],num[1<<12],f[13][1<<12],ans=0x7fffffff;
char BuF[1<<20],*InF=BuF;
template<typename T>void read(T &x){
	for(;*InF<33;++InF);
	for(x=0;32<*InF;x=(x<<3)+(x<<1)+(*InF++^48));
}
inline int lowb(int x){
    return(x&-x);
}
int main(){
	fread(BuF,1,1<<20,stdin);
	read(n);read(m);
	bn=(1<<n)-1;
	if(n==1){
	    putchar(48);
	    return(0);
    }
	for(int i=0;i<n;++i){
		num[1<<i]=i+1;
	}
	memset(a,63,sizeof(a));
	memset(f,63,sizeof(f));
	for(int i=1,x,y,z;i<=m;++i){
		read(x);read(y);read(z);
		a[x][y]=a[y][x]=min(a[x][y],z);
	}
	for(int i=1;i<bn;++i){
		for(int j=1;j<bn;++j){
			if(!(i&j)){
				g[i][++g[i][0]]=j;
			}
		}
	}
	for(int i=1;i<bn;++i){
		for(int j=1;j<=g[i][0];++j){
			for(int k=g[i][j],tk=lowb(k);k;tk=lowb(k-=tk)){
				int mi=0xffffff;
			    for(int l=i,tl=lowb(l);l;tl=lowb(l-=tl)){
					mi=min(mi,a[num[tk]][num[tl]]);
				}
				c[i][j]+=mi;
			}
		}
	}
	for(int i=0;i<n;++i){
		f[0][1<<i]=0;
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<bn;++j){
			for(int k=1;k<=g[j][0];++k){
				f[i][j|g[j][k]]=min(f[i][j|g[j][k]],f[i-1][j]+c[j][k]*i);
				if((j|g[j][k])==(1<<n)-1){
					ans=min(ans,f[i][j|g[j][k]]);
				}
			}
		}
	}
    printf("%d",ans);
	fclose(stdin);
	fclose(stdout);
	return(0);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #133.39 us40 KBAcceptedScore: 5

Testcase #291.36 us492 KBAcceptedScore: 5

Testcase #3685.09 us2 MB + 236 KBAcceptedScore: 5

Testcase #4660.06 us2 MB + 236 KBAcceptedScore: 5

Testcase #5685.75 us2 MB + 236 KBAcceptedScore: 5

Testcase #6229.18 us1 MB + 236 KBAcceptedScore: 5

Testcase #7125.59 us748 KBAcceptedScore: 5

Testcase #8228.74 us1 MB + 236 KBAcceptedScore: 5

Testcase #994.3 us500 KBAcceptedScore: 5

Testcase #10130.75 us752 KBAcceptedScore: 5

Testcase #11230.39 us1 MB + 236 KBAcceptedScore: 5

Testcase #12230.75 us1 MB + 236 KBAcceptedScore: 5

Testcase #13671.86 us2 MB + 236 KBAcceptedScore: 5

Testcase #14688.94 us2 MB + 240 KBAcceptedScore: 5

Testcase #1514.578 ms16 MB + 336 KBAcceptedScore: 5

Testcase #1614.572 ms16 MB + 340 KBAcceptedScore: 5

Testcase #1745.704 ms32 MB + 964 KBAcceptedScore: 5

Testcase #1845.696 ms32 MB + 968 KBAcceptedScore: 5

Testcase #1945.684 ms32 MB + 972 KBAcceptedScore: 5

Testcase #2045.718 ms32 MB + 972 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-25 18:49:03 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠