赞
踩
一个块可以看做是无向图上的边,然后就变成了在无向图上跑欧拉路径。。
4个点应该是可以随便暴力了。。不过边比较多。。
如果考虑哪些边不走,能注意到2条重边可以构成一个简单环。。所以如果不走肯定是亏的。。
所以对重边来说,最多只能不经过一条边。。而本质不同的边其实也就8条。。拆出来就变成16条。。
然后暴力bfs/DP或者直接爆搜应该就可以了。。。
- #include<bits/stdc++.h>
- #define inc(i,l,r) for(int i=l;i<=r;i++)
- #define dec(i,l,r) for(int i=l;i>=r;i--)
- #define link(x) for(edge*j=h[x];j;j=j->next)
- #define mem(a) memset(a,0,sizeof(a))
- #define succ(x) (1<<(x))
- #define lowbit(x) (x&(-x))
- #define ll long long
- #define eps 1e-8
- #define mid (x+y>>1)
- #define sqr(x) ((x)*(x))
- #define NM 1005
- #define nm 200005
- const double pi=acos(-1);
- const int inf=1e9+7;
- using namespace std;
- ll read(){
- ll x=0,f=1;char ch=getchar();
- while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
- while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
- return x*f;
- }
-
-
-
- ll n,ans;
- int m,prime[NM],tot,mu[NM];
- bool v[NM];
-
- void init(){
- m=100;mu[1]=1;
- inc(i,2,m){
- if(!v[i])prime[++tot]=i,mu[i]=-1;
- inc(j,1,tot){
- if(i*prime[j]>m)break;
- v[i*prime[j]]++;
- if(i%prime[j]==0)break;
- mu[i*prime[j]]=-mu[i];
- }
- }
- }
-
-
-
- ll solve(int t){
- ll ans=0;
- ans=(ll)pow(n,1.0/t-eps);
- while(1){
- ll tmp=1;
- bool f=true;
- inc(j,1,t){
- if(n/(ans+1)<tmp){f=false;break;}
- tmp*=ans+1;
- if(tmp>n){f=false;break;}
- }
- if(!f)break;else ans++;
- }
- return ans;
- }
-
- int main(){
- init();
- int _=read();while(_--){
- n=read();ans=0;
- inc(i,2,m){
- ll t=solve(i);
- if(t==1)break;
- ans+=mu[i]*(t-1);
- }
- printf("%lld\n",n+ans-1);
- }
- return 0;
- }
E. Maximum Matching
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given n
blocks, each of them is of the form [color1|value|color2], where the block can also be flipped to get [color2|value|color1
].
A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if the left color of the B is the same as the right color of the A and the right color of the B is the same as the left color of C.
The value of the sequence is defined as the sum of the values of the blocks in this sequence.
Find the maximum possible value of the valid sequence that can be constructed from the subset of the given blocks. The blocks from the subset can be reordered and flipped if necessary. Each block can be used at most once in the sequence.
Input
The first line of input contains a single integer n
(1≤n≤100
) — the number of given blocks.
Each of the following n
lines describes corresponding block and consists of color1,i, valuei and color2,i (1≤color1,i,color2,i≤4, 1≤valuei≤100000
).
Output
Print exactly one integer — the maximum total value of the subset of blocks, which makes a valid sequence.
Examples
Input
Copy
6 2 1 4 1 2 4 3 4 4 2 8 3 3 16 3 1 32 2
Output
Copy
63
Input
Copy
7 1 100000 1 1 100000 2 1 100000 2 4 50000 3 3 50000 4 4 50000 4 3 50000 3
Output
Copy
300000
Input
Copy
4 1 1000 1 2 500 2 3 250 3 4 125 4
Output
Copy
1000
Note
In the first example, it is possible to form a valid sequence from all blocks.
One of the valid sequences is the following:
[4|2|1] [1|32|2] [2|8|3] [3|16|3] [3|4|4] [4|1|2]
The first block from the input ([2|1|4] →
[4|1|2]) and second ([1|2|4] →
[4|2|1]) are flipped.
In the second example, the optimal answers can be formed from the first three blocks as in the following (the second or the third block from the input is flipped):
[2|100000|1] [1|100000|1] [1|100000|2]
In the third example, it is not possible to form a valid sequence of two or more blocks, so the answer is a sequence consisting only of the first block since it is the block with the largest value.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。