zoj_2836 Number Puzzle
2013-06-01 14:56
357 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1836
//C++代码 #include<iostream> using namespace std; int n,m,ans,a[11]; int gcd(int a,int b){ return b==0? a:gcd(b,a%b); } int lcm(int a,int b){ return a/gcd(a,b)*b; } void dfs(int x,int k,int tot){ if(x>0) ans+=k*m/tot; for(int i=x;i<n;i++) dfs(i+1,-k,lcm(a[i],tot)); } int main(){ while(cin>>n>>m){ for(int i=0;i<n;i++) cin>>a[i]; ans=0; dfs(0,-1,1); cout<<ans<<endl; } return 0; }
相关文章推荐
- zoj 1203
- POJ 1751 Highways (ZOJ 2048 ) MST
- zoj_1188 DNA Sorting
- ZOJ 3950 How Many Nines
- ZOJ 4535 ZOJ Monthly, October 2011 H
- ZOJ-1799
- [AC自动机+数位dp] zoj 3494 BCD Code
- zoj——某年某月某日到某年某月某日中9的个数
- zoj 1028 Flip and Shift【水】
- ZOJ-2001
- ZOJ - 3811 Untrusted Patrol(bfs+并查集)
- ZOJ 3953 Intervals (贪心)
- zoj 1167 Tree on the level
- poj2197||zoj2406 Jill's Tour Paths(回溯+优先队列)
- zoj 1260 && poj 1364 King
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- zoj 2165||poj 1979 red and black (dfs)
- POJ 2590 Steps (ZOJ 1871)
- zoj3362 Beer Problem费用流
- ZOJ 1654 Place the Robots建图思维(分块思想)+二分匹配