给 n 中 钱币。以及每两种钱币的关系,表示,ai 的 个数 要大于 bi 组合成一个价值val,求方案数,好奇妙的一个处理方式,不得不说又学到了

#include<stdio.h>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
const int mod = 1e9 + 7;
const int M = 1e5 + 1;
long long dp[M];
int a[500],in[500],father[500]; int main(){
int n,m,t,u,v;
while(cin >> n >> m >> t){ memset(in,0,sizeof(in));
memset(father,0,sizeof(father));
memset(dp,0,sizeof(dp)); int x = m;
// memset(che,0,sizeof(che));
for(int i=1;i<=n;i++) cin >> a[i];
while(m --){
cin >> u >> v;in[v] ++ ;
father[u] = v;
} for(int i=0;i<x;i++){
int pos = 0;
for(int j=1;j<=n;j++){
if(father[j] && !in[j]){
pos = j;break;
}
}
// cout << pos <<endl;
if(!pos){puts("0");return 0;}
int pre = father[pos];
father[pos] = 0;
in[pre] --;
t -= a[pos];
a[pre] += a[pos];
if(t < 0){puts("0");return 0;}
}
dp[0] =1; for(int i=1;i<=n;i++){
for(int j=a[i];j<=t;j++){
dp[j] = (dp[j] + dp[j-a[i]]) % mod;
}
}
//cout << t <<endl;
cout << dp[t] <<endl;
}
}

codeforces 283C的更多相关文章

  1. CodeForces 283C World Eater Brothers

    World Eater Brothers 题解: 树DP, 枚举每2个点作为国家. 然后计算出最小的答案. 首先我们枚举根, 枚举根了之后, 我们算出每个点的子树内部和谐之后的值是多少. 这样val[ ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. [HDU3480] Division [四边形不等式dp]

    题面: 传送门 思路: 因为集合可以无序选择,所以我们先把输入数据排个序 然后发先可以动归一波 设$dp\left[i\right]\left[j\right]$表示前j个数中分了i个集合,$w\le ...

  2. docker (centOS 7) 使用笔记5 - weave网络

    weave官网 https://www.weave.works 1. 下载安装 sudo curl -L git.io/weave -o /usr/local/bin/weave sudo chmod ...

  3. java连接adsl

    http://blog.csdn.net/qq_28784775/article/details/54134169#comments

  4. 物理的alpha blend

    alpha blend主要是可以用来模拟半透明的笔触..然而它是有缺陷的.. 因为一般的alpha blend的(线性混合)模型没有考虑反射光的问题..然而其实反射光是很重要的大家都知道.. 好..如 ...

  5. hihocoder #1407 : 后缀数组二·重复旋律2

    #1407 : 后缀数组二·重复旋律2 Time Limit:5000ms Case Time Limit:1000ms Memory Limit:256MB 描述 小Hi平时的一大兴趣爱好就是演奏钢 ...

  6. LOJ#2307. 「NOI2017」分身术

    $n \leq 100000$个点,$m \leq 100000$次询问,每次问删掉一些点后的凸包面积. 不会啦写个20暴力,其实是可以写到50的.当个计算几何板子练习. //#include< ...

  7. iPhone深度学习-ARM

    平台 xCode 5.0 iPhone 4 在Building setting中的 Architectures 部分,有这么一个选项 Architectures,这里有一些选项是 Armv7 和Arm ...

  8. .NET and php

    原文发布时间为:2011-12-29 -- 来源于本人的百度文章 [由搬家工具导入] http://www.php-compiler.net/blog/2011/phalanger-3-0

  9. practical system design with mef & mef[ trans from arup.codeplex.com/]

    Practical System Design using MEF MVVM RX MOQ Unit Tests in WPF Posted on May 21, 2015 by Arup Baner ...

  10. Bazinga 题解

    第十四届浙江财经大学程序设计竞赛重现赛-B题 https://www.nowcoder.com/acm/contest/89/B 可能最近,脑子有问题,看见数论题都是秒,学弟问我这题怎么做,结果我沉思 ...