아니 제가 얼마전에 수학학원을 그만두고 그 교재로 엄마랑 하는데, 그게 답안지가 없어서 엄마도 일일이 구해야 하는데, 둘다 계속 답이 안 맞는게
012344카드로 짝수 네자리수 만들수있는 개수는?
입니다.
도와주세요....
코드를 짜봤어요.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, n) for (int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pi;
const int MAX = (int)1e5 + 5;
multiset<int> ms;
string s; int cnt;
void dfs(int depth)
{
if (depth > 4)
{
if ((s.back() - '0') % 2 == 0 && s[0] != '0')
{
cout << s << '\n';
cnt++;
}
return;
}
vector<int> vc;
auto it = ms.begin();
for (it = ms.begin(); it != ms.end(); it++) vc.push_back(*it);
sort(all(vc)); vc.erase(unique(all(vc)), vc.end());
for (int each : vc)
{
it = ms.lower_bound(each); ms.erase(it);
s += to_string(each);
dfs(depth + 1);
s = s.substr(0, (int)s.size() - 1);
ms.insert(each);
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cout << fixed; cout.precision(7);
ms.insert(0);
ms.insert(1);
ms.insert(2);
ms.insert(3);
ms.insert(4);
ms.insert(4);
dfs(1);
cout << "\n" << cnt << '\n';
return 0;
}
107개래요.
이런 이런 수들이 있대요.
정확하다고 보장은 못합니다.(???????)
1024
1032
1034
1042
1044
1204
1230
1234
1240
1244
1302
1304
1320
1324
1340
1342
1344
1402
1404
1420
1424
1430
1432
1434
1440
1442
2014
2034
2044
2104
2130
2134
2140
2144
2304
2310
2314
2340
2344
2404
2410
2414
2430
2434
2440
3012
3014
3024
3042
3044
3102
3104
3120
3124
3140
3142
3144
3204
3210
3214
3240
3244
3402
3404
3410
3412
3414
3420
3424
3440
3442
4012
4014
4024
4032
4034
4042
4102
4104
4120
4124
4130
4132
4134
4140
4142
4204
4210
4214
4230
4234
4240
4302
4304
4310
4312
4314
4320
4324
4340
4342
4402
4410
4412
4420
4430
4432