1、给出一个$n$个顶点的无向带权图。其中顶点$i,i+1$之间存在边,$i,i+2$之间存在边。而且仅有这些边。现在删掉其中的一些边,剩下的边满足图仍然是2联通的情况下使得权值和最小?

思路:其实就是使得删掉的边的权值最大。对于第$i$和第$i+1$个顶点,2联通的两条路径一定经过了$e(i,i+1),e(i-1,i+1),e(i,i+2)$中的两个。也就是说这三条边最多只能删除其中的一条。现在从左向右依次考虑每个顶点。设$f[i]$表示顶点$i$之前的边已经全部考虑(不能删除$e(i-1,i+1)$了,因为它被当做是在$i$之前的边)。那么如果删掉了$e(i,i+1)$,那么后面就考虑顶点$i+1$;如果删除了$e(i,i+2)$,那么后面就直接考虑顶点$i+2$。因为$i+1$处其他的边不能再删除了。

#include <stdio.h>
#include <string>
#include <stack>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std; int f[105]; class BiconnectedDiv1
{
public:
int minimize(vector<int> w1,vector<int> w2)
{
const int n=(int)w1.size()+1;
int s=0;
for(int i=0;i<n-1;++i) s+=w1[i];
for(int i=0;i<n-2;++i) s+=w2[i]; for(int i=1;i<n-2;++i) {
f[i+1]=max(f[i+1],f[i]+w1[i]);
f[i+2]=max(f[i+2],f[i]+w2[i]);
}
return s-f[n-2];
}
};

2、构造一个二分图,左右的顶点个数相同但是不大于20且完美匹配恰好有$K$个。可以有重边

思路:构造思路是用3进制。

#include <stdio.h>
#include <string>
#include <stack>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std; class BipartiteConstruction
{
public:
vector<int> construct(int K)
{
vector<int> ans;
if(K==0)
{
ans.push_back(2);
ans.push_back(1);
ans.push_back(0);
return ans;
}
if(K==1)
{
ans.push_back(1);
ans.push_back(0);
return ans;
}
ans.push_back(20);
for(int i=0;i<19;++i) ans.push_back(i*20+i+1);
for(int i=2;i<20;++i) ans.push_back(i*20+i),ans.push_back(i*20+i),ans.push_back(i*20+i);
for(int i=19;i>=1;--i)
{
for(int j=0;j<K%3;++j) ans.push_back(i*20);
K/=3;
}
return ans; }
};

  

topcoder srm 693 div1 -3的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  7. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  8. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

  9. topcoder srm 575 div1

    problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...

随机推荐

  1. animator 新动画

    using System.Collections; using System.Collections.Generic; using UnityEngine; public class Animator ...

  2. 合并dict、list的方法

    dict1={1:[1,11,111],2:[2,22,222]}dict2={3:[3,33,333],4:[4,44,444]}合并两个字典得到类似 {1:[1,11,111],2:[2,22,2 ...

  3. SpringBoot+SpringCloud实现登录用户信息在微服务之间的传递

    实现思路: 1:准备一个ThreadLocal变量,供线程之间共享. 2:每个微服务对所有过来的Feign调用进行过滤,然后从请求头中获取User用户信息,并存在ThreadLocal变量中. 3:每 ...

  4. html5-css边框全

    /*div{    width: 500px;    height: 300px;    background: rgb(122,30,60);    border: 10px solid black ...

  5. 异常点/离群点检测算法——LOF

    http://blog.csdn.net/wangyibo0201/article/details/51705966 在数据挖掘方面,经常需要在做特征工程和模型训练之前对数据进行清洗,剔除无效数据和异 ...

  6. 任务调度工具 Apache Airflow 初识

    参考文章: Apache Airflow (incubating) Documentation — Airflow ... 任务调度神器 airflow 之初体验 airflow 介绍 - 简书(原文 ...

  7. nodejs之pm2自动重启服务

    pm2 start xxx #启动服务器 pm2 list #查看运行状态 pm2 logs #查看日志 pm2 restart xxx #重启应用 pm2 stop xxx #停止应用 监听修改,并 ...

  8. HADOOP nutch java mysql

    下载Hadoop安装包 wget  http://apache.fayea.com/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz   java安装 wg ...

  9. python 关键字yield解析

    python 关键字yield解析 yield 的作用就是把一个函数变成一个 generator,带有 yield 的函数不再是一个普通函数,Python 解释器会将其视为一个 generator.y ...

  10. <转>jmeter(十一)JDBC Request之Query Type

    本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...