当前位置: 代码迷 >> Exchange >> 搜寻:zoj 2734 Exchange Cards(DFS)
  详细解决方案

搜寻:zoj 2734 Exchange Cards(DFS)

热度:6728   发布时间:2013-02-26 00:00:00.0
搜索:zoj 2734 Exchange Cards(DFS)

【转】http://blog.csdn.net/zxy_snow/article/details/6005768

?

#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int sum,ways;int num[1010];int value,n;void DFS(int x){	if( sum == value )	{		ways++;		return ;	}	for(int i=x; i<=value; i++)	{		if( num[i] && sum + i <= value )		{			num[i]--;			sum += i;			DFS(i);			num[i]++;			sum -= i;		}	}}int main(void){	int x,y;	int pe = 0;	while( cin >> value >> n )	{		if( pe )			cout << endl;		pe = 1;		memset(num,0,sizeof(num));		sum = ways = 0;		for(int i=0; i<n; i++)		{			cin >> x >> y;			num[x] = y;		}		DFS(1);		cout << ways << endl;	}return 0;}

?

  相关解决方案