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 ...
随机推荐
- Linux——shell简单学习(一)
首先来一个小程序,来查看所在目录,以及该目录下的文件 #!/bin/sh # “#!”指定用sh执行shell脚本 #this is to show workstation # “#” 表示注释 ec ...
- 深入理解Hadoop之HDFS架构
Hadoop分布式文件系统(HDFS)是一种分布式文件系统.它与现有的分布式文件系统有许多相似之处.但是,与其他分布式文件系统的差异是值得我们注意的: HDFS具有高度容错能力,旨在部署在低成本硬件上 ...
- Java 常用对象-StringBuffer类
2017-11-02 20:57:02 StringBuffer:线程安全的可变字符序列.一个类似于 String 的字符串缓冲区,但不能修改.虽然在任意时间点上它都包含某种特定的字符序列,但通过某些 ...
- C#快速生成数据数组
需求:生成一个数组,数组里面的值为1-100实现方式:拿到这个需求很多朋友可能会想到一个快速实现的方式如下: ]; ;i<=;i++){ arr[i]=i; } 但是C#提供了一个快速生成的方式 ...
- 在浏览器外打开PDF文档
One function you might find annoying with PDFs and PDF Readers is that when you click on a link to a ...
- English trip -- VC(情景课)2 D Reading
Xu言: 业精于勤,荒于嬉:行成于思,毁于随 Before you read 阅读准备 Talk about the picture, what do you see?看图说话,你看到了什么? Lis ...
- IntelliJ IDEA 进行多线程调试
idea的断点有不同的模式,只有当Thread模式下才能调试多线程 断点设置步骤: 1.在断点上右键 2.选择Thread,然后点Done(建议选择Thread后点击make default把 ...
- TCP/IP四层与OSI七层模型
OSI七层和TCP/IP四层的关系 1.1 OSI引入了服务.接口.协议.分层的概念,TCP/IP借鉴了OSI的这些概念建立TCP/IP模型. 1.2 OSI先有模型,后有协议,先有标准,后进行实 ...
- UVA-1579 Matryoshka (区间DP)
题目大意:n个俄罗斯套娃,都有相应的编号,每次可将两个相邻的套娃组合成一组,每次合成只能小的放到大的里面,并且是逐层嵌套.问将这n个套娃分成若干个组,并且每组都是编号从1开始的连续序列,最少需要几步. ...
- Android studio jni
首先我们要明确几个概念,jni,ndk,共享库(.so). jni是java native interface的缩写,java 本地接口.它提供了若干的API实现了Java和其他语言的通信(主要是C/ ...