poj.2586dfs
来源:互联网 发布:死飞淘宝店 编辑:程序博客网 时间:2024/05/28 17:06
这道题目的意思是有12个月,每个月要么盈利s,要么亏损d,没连续五个月就又一次上表,总共有八次note,每次都亏损,现给出s和d,要求如果有盈利的情况,求出盈利情况中盈利最多的数目,否则就输出"Deficit“这道题总共有2^16中可能,可以用dfs枚举每种可能,然后求出满足题意的盈利最大值。思路很简单,下面是代码:
#include <stdio.h>#include <stdlib.h>int s[12];int Max;int n,m;bool Is_right(int *t){int i;for(i=0;i<8;i++){int temp=t[i]+t[i+1]+t[i+2]+t[i+3]+t[i+4];if(temp>=0)return false;}return true;}void dfs(int *p,int deep){if(Is_right(p)){int sum=0;for(int i=0;i<12;i++)sum+=p[i];if(sum>Max)Max=sum;}if(deep>=12)return ;int record[12];for(int i=0;i<12;i++)record[i]=p[i];record[deep]=n;dfs(p,deep+1);dfs(record,deep+1);}int main(){while(scanf("%d%d",&n,&m)!=EOF){int i;for(i=0;i<12;i++)s[i]=-m;Max=-1;dfs(s,0);if(Max>=0)printf("%d\n",Max);elseprintf("Deficit\n");}return 0;}
- poj.2586dfs
- DFS POJ
- POJ DFS
- poj 3083 DFS+DFS+BFS
- POJ 1753 ID+DFS
- poj 1950 数字dfs
- poj 1816(trie+dfs)
- POJ 3107 Godfather(DFS)
- poj 3620(DFS)
- poj 1020 DFS
- poj 2362Square(DFS)
- POJ 2676 Sudoku dfs
- POJ 2357 Labyrinth [DFS]
- poj 1011 dfs
- poj 1190 dfs(生日蛋糕)
- poj 1154 dfs
- poj 2192 DFS+剪枝
- 【DFS】POJ 2044
- 使用JNI进行Java与C/C++语言混合编程(1)--在Java中调用C/C++本地库
- Android应用开发——数据库分析
- Class.newInstance()与new、Constructor.newInstance()的区别
- 只列出这个字段中有数值的行
- keytool命令总结
- poj.2586dfs
- hdu4609 FFT+计数 经典
- 类
- UINavigationController详解与使用(三)ToolBar
- jdbc的介绍与使用示例
- hdu 1007 Quoit Design(分治法)
- POJ 3169 —— 差分约束的最短路解法
- 鼠鼠百科--图灵机
- 求100米赛跑运动员的成绩