#include <la iostream> el uso de espacio de nombres STD; int n-, SUM; int NUM [ 105 ]; BOOL F; BOOL VIS [ 105 ]; void DFS ( int COUNT, int sum1, int Posit) { IF (F) { retorno ; } // encuentra retorno directo SI (COUNT == 3. {) F = true ; de retorno ; } // encontrar el 3 SI (SUMA sum1 == / . 3) { DFS (COUNT + 1. , 0 , 0 ); retorno ; } // encontrar el uno para ( int I = 0 ; I <n-; I ++ ) { IF ! ( VIS [I]) { VIS [I] = . 1 ; DFS (COUNT, sum1 + NUM [I], I + 1. ); VIS [I] = 0 ; } } // comenzar una búsqueda no se encontró otra vez, y luego la etiqueta y luego continuar la búsqueda, tomar norma } int main () { CIN >> n-; para ( int i = 0 ; i <n; i ++ ) { cin >> num [i]; suma + = num [i]; } Si (suma% 3 =! 0 ) { cout << " ¡No! " << endl; } Else { DFS ( 0 , 0 , 0 ); si (f) { cout << " Sí! " << endl; } } Devolver 0; }
Estos problemas uno por uno búsqueda con DFS, encontrar la estrategia de búsqueda, el juez entonces las condiciones límite dadas pueden ser resueltos