码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 283C

时间:2017-04-29 23:37:05      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:方案   code   ++   fat   val   组合   return   stdio.h   stream   

给 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

标签:方案   code   ++   fat   val   组合   return   stdio.h   stream   

原文地址:http://www.cnblogs.com/gavanwanggw/p/6786398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!