给 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. FZU 2041 二分枚举

    思路:先O(n)预处理出ri[i][j],le[i][j],分别表示第i个位置向右边移动出j个空格需要的步数,表示第i个位置向左边移动出j个空格需要的步数. 然后枚举间隙处,二分判段最大间隔. #in ...

  2. 几种API接口

    实用号码归属地查询(IP 地址,手机号码): 默认格式: http://api.liqwei.com/location/ (使用来访者的 IP 地址) 指定 IP 地址格式: http://api.l ...

  3. C++ qsort() 函数调用时实参与形参不兼容的问题解决

    <剑指OFFER>刷题笔记 —— 扑克牌顺子 LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自 ...

  4. html5 的 webScoket 和 C# 建立Socket连接

    最近使用的web项目中,需要服务器直接触发前端显示效果. 所以研究了一下websocket: 名词解释: WebSocketWebSocket协议是一种双向通信协议,它建立在TCP之上,同http一样 ...

  5. 很好用的取代 PuTTY 的SSH远程登陆软件 Termius

    一直以来, 我都是用 PuTTY 一个窗口一个窗口来监视我所有的远程服务器. putty-connections-on-a-screen 总感觉非常的不方便, 特别是当远程链接断开需要再重新打开PUT ...

  6. 写一个Foreach帮助类,在razor中使用

    原文发布时间为:2011-05-05 -- 来源于本人的百度文章 [由搬家工具导入] A Better Razor Foreach Loop(razor delegate extension) htt ...

  7. ThreadPool学习草稿1

    原文发布时间为:2010-10-27 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Collections.Generic;using Syste ...

  8. linux下的程序调试方法汇总

    搞电子都知道,电路不是焊接出来的,是调试出来的.程序员也一定认同,程序不是写出来的,是调试出来的.那么调试工具就显得尤为重要,linux作为笔者重要的开发平台,在linux中讨论调试工具主要是为那些入 ...

  9. msm8917 GPIO Voh(min)

    有些 pin 可以當成多種 function, 此例以 GPIO function P3 voltage 為例 Voh(min) = 1.67 - 0.45 = 1.22 V

  10. 设置div自适应高度滚动

    <body> <div id="divc" style="overflow: auto;"> </div> <a id ...