NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms
Memory limit 131072 kB
It is widely known that any two strangers can get to know each other through at most six other people. Now let’s prove this.
In the country Intermediary Conducts Personal Communications (ICPC), there are up to n (2<=n<=100) ordinary people conveniently numbered from 0 to n-1. They don’t know each other, or, in other words, they are strangers. The only way they can communicate with each other is through the government, which, in fact, is an intermediary agency. The government consists of up to m (1<=m<=9) employees conveniently numbered from 0 to m-1. Suppose employee z can introduce person x to person y at a cost of d dollars. If this is the first time in a day that employee z introduce one person to another, he will only require d dollars. For the second time, he will require d dollars plus extra e dollars as his tip. For the third time and more, he will require d dollars plus extra f dollars. He is not dared to require any more than that since the strange country is somewhat democratic. And if person x is able to communicate with person t and person t is able to communicate with person y, then person t is always willing to transfer messages from person x to person y, at no charge. Of course, the intermediary fees are all paid by person x. Notice that employee z being able to introduce person x to person y doesn’t mean he can introduce person y to person x.
Now person 0 has to send a message to person n-1 in one day. If all employees have just started to work, what is the minimum cost for person 0?
Input
Proceed to the end of file.
Output
Sample Input
3 2 2
1 1
2 2
0 1 0 1
1 2 1 2 5 1 4
1
2
0 1 0 1
1 2 0 1
2 3 0 1
3 4 0 1
Sample Output
3
9 自己还没懂,记了网上大牛的代码。。就是这样 http://blog.csdn.net/ttl_135678942570/article/details/8068149
#include<cmath>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<numeric>
#include<vector>
#include<ctime>
#include<queue>
#include<list>
#include<map>
#define pi acos(-1)
#define INF 0x7fffffff
#define clr(x) memset(x,0,sizeof(x));
#define clrto(x,siz,y) for(int xx=0;xx<=siz;xx++) x[xx]=y;
#define clrset(x,siz) for(int xx=0;xx<=siz;xx++) x[xx]=xx;
#define clrvec(x,siz) for(int xx=0;x<=siz;xx++) x[xx].clear();
#define fop freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define myprogram By_135678942570
#define clrcpy(x,siz,y) for(int xx=0;xx<siz;xx++) x[xx]=y[xx];
using namespace std;
struct node
{
int val;
int emp;
int to;
};
vector<node>road[];
int e[]={};
int f[]={};
int use[]={};
int vis[]={};
int n,m,q;
long long minn=INF;
void find(int pos,int sum)
{
if(sum>=minn)
return;
if(pos==n-)
{
minn=sum;
return;
}
for(int i=;i<road[pos].size();i++)
{
int next=road[pos][i].to;
if(!vis[next])
{
vis[next]=;
int k=road[pos][i].emp;
int c=road[pos][i].val;
use[k]++;
if(use[k]==)
find(next,sum+c);
else if(use[k]==)
find(next,sum+c+e[k]);
else find(next,sum+c+f[k]);
vis[next]=;
use[k]--;
}
}
}
main()
{
while(scanf("%d%d%d",&n,&m,&q)!=EOF)
{
clr(vis);
clr(use);
for(int i=;i<=;i++)
road[i].clear();
for(int i=;i<m;i++)
scanf("%d",e+i);
for(int i=;i<m;i++)
scanf("%d",f+i);
for(int i=;i<q;i++)
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
node temp;
temp.to=b;
temp.val=d;
temp.emp=c;
road[a].push_back(temp);
}
minn=INF;
find(,);
if(minn==INF)
puts("-1");
else printf("%d\n",minn);
}
return ;
}
NBUT 1221 Intermediary 2010辽宁省赛的更多相关文章
- NBUT 1220 SPY 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- NBUT 1217 Dinner 2010辽宁省赛
Time limit 1000 ms Memory limit 32768 kB Little A is one member of ACM team. He had just won the g ...
- NBUT 1224 Happiness Hotel 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The life of Little A is good, and, he managed to get enoug ...
- NBUT 1222 English Game 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...
- NBUT 1225 NEW RDSP MODE I 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A has became fascinated with the game Dota recent ...
- NBUT 1218 You are my brother 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...
- NBUT 1223 Friends number 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
- ZOJ 1985 Largest Rectangle in a Histogram(刷广告)2010辽宁省赛
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21204 ...
随机推荐
- UVa 253 骰子涂色
https://vjudge.net/problem/UVA-253 题意:输入两个骰子的六面颜色,判断是否等价. 思路:我最想到的是暴力,不过一直错,也不知道哪里错了.第二种方法就是在一个骰子里出现 ...
- ros rviz 启动指定的rviz 文件
rviz -d rviz文件名 例如:rviz -d myname.rviz
- ZC_C++类函数指针_模拟_Delphi类函数指针
ZC: C++的类函数指针 不像 Delphi的类函数指针,前者 需要规定死 是哪个类的函数的指针,后者就不需要 很灵活. 测试环境: Win7x64 cn_visual_studio_2010_ul ...
- shell 命令行光标跳转快捷键和history的用法
Ctrl+a: 跳到命令行首 Ctrl+e: 跳到命令行尾 Ctrl+u: 删除光标至命令行首的内容 Ctrl+k: 删除光标至命令行尾的内容 Ctrl+<- 跳到前一个单词首部 Ctrl+-& ...
- spark必知必会的基本概念
首先我们从宏观的视角来窥视下大数据技术框架: 图1 大数据技术框架 从图1可以看出,数据源-数据收集-数据存储-资源管理,这是我们进行数据分析和处理的基本;图中的计算框架包括批处理.交互式分析和流处理 ...
- 《剑指offer》第三_二题(不修改数组找出重复的数字)
// 面试题3(二):不修改数组找出重复的数字 // 题目:在一个长度为n+1的数组里的所有数字都在1到n的范围内,所以数组中至 // 少有一个数字是重复的.请找出数组中任意一个重复的数字,但不能修改 ...
- es5,es6,typescript,nodejs
es5新特性 讲到js必讲的几个概念,作用域,闭包,IIFE自执行函数 es5主要是对Object,Array,Function做了扩展,还有josn工具 es6新特性 增加了新的数据类型 WeakM ...
- C++ 利用栈解决运算问题
2017-06-27 19:19:18 第一步需要将中缀表达式转为后缀表达式.这步的转化可以说是本题的核心. 主要的转化手段是利用栈,有如下几个规则: 数字直接输出 "("直接进栈 ...
- English trip V1 - 4.Do you have it? Teacher:Patrick Key: have - has doesn't have
In this lesson you will learn to describe what you have. STARTER Do you have a ...? # 你有...吗? car b ...
- English trip -- VC(情景课)10 A Get ready 预备课
Words dance 跳舞 exercise 运动:锻炼 fish 鱼 play basketball 打篮球 play cards 玩牌 swim 游泳 decorations 装饰品 ...