今天学习了《穷举》俗称:“爆算”,当然爆的是内存,及《递推递归分治》以下是关于《穷举》的一题的题解:
#include
using namespace std;
int ans = 0,la,lb,L[20],R[20];
void pri(int <em>s,int l) {
for (int i = 0; i < l; i++) printf("%d",</em>(s+i));
printf("\n");
}
int cmp(int <em>a,int *b,int l) {
for (int i = 0; i < l; i++) {
if (</em>(a+i) *(b+i)) return 1;
}
return 0;
}
void count(int l) {
int s[20];
for (int i = 0; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
if (j <span class="text-highlighted-inline" style="background-color: #fffd38"> i) continue;
for (int k = 0; k < l; k++) {
for (int tmp = 0; tmp < l; tmp++) s[tmp] = i;
s[k] = j;
if (s[0] </span> 0) continue;
if (la < l&&l 0)) continue;
if (l <span class="text-highlighted-inline" style="background-color: #fffd38"> lb&&(cmp(s,R,l) > 0)) continue;
ans++;
}
}
}
}
}
int main() {
freopen("odometer.in","r",stdin);
freopen("odometer.out","w",stdout);
char A[20],B[20];
scanf("%s%s",&A,&B);
la = strlen(A);
lb = strlen(B);
for (int i = 0; i < la; i++) L[i] = A[i] - '0';
for (int i = 0; i < lb; i++) R[i] = B[i] - '0';
for (int i = la; i <= lb; i++) count(i);
printf("%d\n",ans);
return 0;
}
也是领略了到了那种一写就爆炸的快感。
想到明天要进行小模拟内心就有点慌,怕难度太高。
算了,好好应对吧!
乐