当前位置:网站首页>Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
2022-07-02 21:41:00 【Woodenman Du】
Question:

Result:64
Solve:
DFS to flash back , Just try one by one and fill in a few , And then TLE 了
Two questions :
First of all : Run completely 13 Try a few , Will be Fried , We need to get rid of the impossible plan in advance , For example, fill in the first line , I'll see if the first formula works
second : Division in the standard answer of this question is only divisible , instead of “/”, Then it led me to look at my 1376 Dazed for a long time , Great speechless event
Code:
#include <bits/stdc++.h>
using namespace std;
bool a[14];
int num[13];
int res = 0;
void dfs(int deep)
{
// Remove in advance
if(deep > 3 && num[1] + num[2] != num[3])return ;
if(deep > 6 && num[4] - num[5] != num[6])return ;
if(deep > 9 && num[7] * num[8] != num[9])return ;
// Final judgment
if(deep > 12)
{
if(num[10] / num[11] == num[12] && num[10]%num[11] == 0)
res++;
return ;
}
// Search for
for(int i = 1; i <= 13; i++){
if(a[i] == true) continue;
num[deep] = i; a[i] = true;
dfs(deep+1);
// to flash back
a[i] = false;
}
}
int main(void)
{
memset(a,false,sizeof(a));
dfs(1);
cout <<res;
return 0;
}Statement : The pictures are from the official website of the Blue Bridge Cup , For the purpose of sorting out personal questions , In case of infringement , Please contact to delete ~
边栏推荐
- 如何防止你的 jar 被反编译?
- What is the difference between programming in real work and that in school?
- Sword finger offer (II) -- search in two-dimensional array
- kernel_ uaf
- It is said that this year gold three silver four has become gold one silver two..
- [shutter] statefulwidget component (pageview component)
- 7. Build native development environment
- Happy Lantern Festival! Tengyuanhu made you a bowl of hot dumplings!
- China Indonesia advanced wound care market trend report, technological innovation and market forecast
- Who do you want to open a stock account? Is it safe to open a mobile account?
猜你喜欢

Capacity expansion mechanism of ArrayList
![[dynamic planning] p1220: interval DP: turn off the street lights](/img/b6/405e29ca88fac40caee669a3b7893f.jpg)
[dynamic planning] p1220: interval DP: turn off the street lights

rwctf2022_ QLaaS

MySQL learning record (5)

Three chess games
![[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)](/img/80/215499c66243d5a4453d8e6206c012.jpg)
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)

How to test the process of restoring backup files?

VictoriaMetrics 简介

基本IO接口技术——微机第七章笔记

Unexpectedly, there are such sand sculpture code comments! I laughed
随机推荐
It is said that this year gold three silver four has become gold one silver two..
Capacity expansion mechanism of ArrayList
China's crude oil heater market trend report, technological innovation and market forecast
Market trend report, technical innovation and market forecast of China's Micro pliers
When Valentine's Day falls on Monday
Cardinality sorting (detailed illustration)
Common authority query instructions in Oracle
Go web programming practice (2) -- process control statement
Analysis of enterprise financial statements [4]
[12] the water of the waves is clear, which can wash my tassel. The water of the waves is muddy, which can wash my feet
Research Report on market supply and demand and strategy of microplate instrument industry in China
Research Report on minimally invasive medical robot industry - market status analysis and development prospect prediction
[shutter] shutter layout component (physicalmodel component)
Detailed explanation of OSI seven layer model
mysql
MySQL learning record (9)
Who do you want to open a stock account? Is it safe to open a mobile account?
[shutter] statefulwidget component (image component | textfield component)
PIP version update timeout - download using domestic image
Research Report on market supply and demand and strategy of China's Plastic Geogrid industry