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 208 消防车(dfs+剪枝)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- ThreadPool开启多线程时支持最大连接200个(默认为2个),不加则会超时
//ThreadPool System.Net.ServicePointManager.DefaultConnectionLimit = 200;
- C++:delete不完整类型的指针
简单版 以下代码编译时会有warning: class X; void foo(X* x) { delete x; } 在GCC4.1.2下,编译出错信息是: warning: possible pr ...
- Could not find a package configuration file provided by 'ecl_threads' ,.................couldn't find required component 'ecl_threads'
sudo apt-get install ros-kinetic-ecl-threads
- pip 安装pandas报UnicodeDecodeError: 'ascii' codec can't decode byte 0xd5错
当Python在window环境中通过pip安装pandas报标题这样的错,主要是因为python默认编码格式是:ascii 在https://www.python.org/dev/peps/pep- ...
- 基于 Flutter 以两种方式实现App主题切换
概述 App主题切换已经成为了一种流行的用户体验,丰富了应用整体UI视觉效果.例如,白天夜间模式切换.实现该功能的思想其实不难,就是将涉及主题的资源文件进行全局替换更新.说到这里,我想你肯定能联想到一 ...
- Codeforces 614E - Necklace
614E - Necklace 思路:如果奇数超过1个,那么答案是0:否则,所有数的gcd就是答案. 构造方案:每个数都除以gcd,如果奇数个仍旧不超过1个,找奇数个那个在中间(如果没有奇数默认a), ...
- GitHub 中国区前 100 名到底是什么样的人?
转一下CSDN的文章, 这里有些人挺厉害的. http://geek.csdn.net/news/detail/66000
- android--------阿里 AndFix 热修复
AndFix,全称是Android hot-fix.是阿里开源的一个热补丁框架,允许APP在不重新发布版本的情况下修复线上的bug. 支持Android 2.3 到 6.0,并且支持arm 与 X86 ...
- nyoj860(01变形)
http://acm.nyist.net/JudgeOnline/problem.php?pid=860 又见01背包 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 ...