给 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. [ZJOI2014][bzoj3527]力 [FFT]

    题面 传送门 思路 把要求的公式列出来: $E_i=\frac{F_i}{q_i}=\sum_{j=1}^i\frac{q_j}{\left(i-j\right)^2}-\sum_{j=i+1}^n\ ...

  2. [SDOI2015][bzoj3994] 约数个数和 [莫比乌斯反演]

    题面: 传送门 思路: 首先,我们需要证明一个结论:d(i*j)等于sigma(gcd(x,y)==1),其中x为i的约数,y为j的约数 对于nm的每一个质因子pi分别考虑,设n = pi^ai + ...

  3. Java面试题之Integer.valueOf(String s);采用了什么设计模式

    Integer.valueOf(String s);//采用了亨元设计模式: 亨元模式: 它是以一种“节约内存,提高性能”为出发点的设计模式,运用共享技术有效的支持大量细粒度对象的复用. 源码解析: ...

  4. 序列操作(bzoj 1858)

    Description lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 ...

  5. BZOJ 3513: [MUTC2013]idiots

    3513: [MUTC2013]idiots Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 476  Solved: 162[Submit][Stat ...

  6. Xcode打包和生成ipa文件

    1.生成Archive文档 a) 需将左上角红色方框里的设备类型选为ios device,不能选择具体的设备类型,否则不能生成Archive文档: b) 中部选择Team的方框,可此时选,也在后续ex ...

  7. 【winform】基于UserControl实现webBrower组件时html页面元素加载及onclick事件监听实现

    [背景]基于System.Windows.Forms.UserControl实现的webBrower组件在html内使用window.external调用winform事件失败. [解决思路]借助wi ...

  8. 从头实现一个koa框架

    koajs是最流行的nodejs后端框架之一,有很多网站都使用koa进行开发,同时社区也涌现出了一大批基于koa封装的企业级框架.然而,在这些亮眼的成绩背后,作为核心引擎的koa代码库本身,却非常的精 ...

  9. [LeetCode] Gas Station 贪心

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  10. 用python获取服务器硬件信息[转]

    #!/usr/bin/env python # -*- coding: utf-8 -*- import rlcompleter, readline readline.parse_and_bind(' ...