给 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. bzoj 4292: [PA2015]Równanie

    Description 对于一个正整数n,定义f(n)为它十进制下每一位数字的平方的和.现在给定三个正整数k,a,b,请求出满足a<=n<=b且k*f(n)=n的n的个数.   Input ...

  2. 编码风格——linux内核开发的coding style

    总结linux内核开发的coding style, 便于以后写代码时参考. 下面只是罗列一些规则, 具体说明可以参考: 内核源码(Documentation/CodingStyle) 01 - 缩进 ...

  3. css iframe边框去掉

    [IE6以下] iframe边框通过css设定在FF下正常在ie下却还存在边框,通过在iframe标签内部设置属性 frameborder="no" border="0& ...

  4. react之只用classNames避免字符串拼接

    之前在react当中使用了字符串拼接的方式来拼接类名的字符串,这种方法不仅不够方便,还会出现很多问题 使用classNames这个工具,可以省去拼接字符串的烦恼,大大提高开发效率 首先,最简单的使用方 ...

  5. Repeater的使用及其鼠标特效,行链接的使用

    原文发布时间为:2009-04-22 -- 来源于本人的百度文章 [由搬家工具导入] <asp:Repeater ID="rpt" runat="server&qu ...

  6. hdu 5972 Regular Number 字符串Shift-And算法 + bitset

    题目链接 题意 给定两个串\(S,T\),找出\(S\)中所有与\(T\)匹配的子串. 这里,\(T\)的每位上可以有若干(\(\leq 10\))种选择,匹配的含义是:对于\(S\)的子串的每一位, ...

  7. BusyBox 简化嵌入式 Linux 系统【转】

    转自:http://www.cnblogs.com/hnrainll/archive/2011/06/10/2077393.html BusyBox 的诞生 BusyBox 最初是由 Bruce Pe ...

  8. LeetCode OJ-- Add Binary

    https://oj.leetcode.com/problems/add-binary/ 对两个二进制字符串求和. 对于字符串 ans_str,求它的翻转. reverse(ans_str.begin ...

  9. Codeforces 158 B. Taxi[贪心/模拟/一辆车最多可以坐4人同一个群的小朋友必须坐同一辆车问最少需要多少辆车]

    http://codeforces.com/problemset/problem/158/B B. Taxi time limit per test 3 seconds memory limit pe ...

  10. C++面向对象程序设计_Part1

    目录 C++历史 C++的组成 C++ 与 C 的数据和函数区别 基于对象与面向对象的区别 C++类的两个经典分类 头文件防卫式声明 头文件的布局 类的声明 类模板简介 内联(inline)函数 访问 ...