Last active
August 29, 2015 14:07
-
-
Save Yazaten/3476a50b94a2435fe6bc to your computer and use it in GitHub Desktop.
(DROP_SUM) C (DROP_ATK) 通り全列挙
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define DROP_ATK 15 | |
#define DROP_SUM 30 | |
/************************************************* | |
OneSum numマス目までで、いくつ'1'を配置したかを表す | |
num 現在何マス目かを表す | |
loc numマス目までの配置を記録する | |
*************************************************/ | |
void dfs(int OneSum,int num,char loc[30]){ | |
if( num==DROP_SUM ){ printf("%s",loc); return ; } | |
if( !( DROP_ATK==OneSum + ( DROP_SUM-num ) ) ){ //「ここで'1'を置かなければ、'1'の合計がDROP_ATKに満たない」という状態でなければ、以下を実行 | |
loc[num]='0'; | |
dfs( OneSum ,num+1 ,loc ); | |
} | |
if( OneSum<DROP_ATK ){ //「現在の'1'の合計がDROP_ATKより少ない」時、以下を実行 | |
loc[num]='1'; | |
dfs( OneSum+1 ,num+1 ,loc ); | |
} | |
} | |
int main(){ | |
char loc[30]={}; //ドロップ配置用配列(location) | |
dfs(0,0,loc); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment