BZOJ 1695 [Usaco2007 Demo]Walk the Talk 链表+数学

题意:链接

方法:乱搞

解析:

出这道题的人存心报复社会。

首先这个单词表…先上网上找这个单词表…

反正总共2265个单词,然后就考虑怎么做就行了。

刚开始我没看表,找不到怎么做,最快的方法我也只是想到了类n^6的做法。

然后我就卡关辣,这关怎么过!

神犇的方法是:观察表,发现规律:

发现表中的单词最长就是4个字母。

所以我们可以考虑求1,2,3,4长度的单词数。

1的话可以直接记录,扫的时候顺带加上就行。

然后神犇说了一句话:

表中长度为4的单词前两个字母相同的单词个数不超过35个。

长度为3前一个字母相同的单词个数不超过7个。

所以直接上链表优化啊?

这样的话就要求我们预处理什么呢?

预处理点(i,j)右上角字母x的出现次数。

预处理点(i,j)右上角后缀xy的出现次数。

这个怎么维护啊?

容斥原理啊,所以复杂度在26*26*nm左右,也就是4次方,可以接受。

所以我们只需要枚举开头的两个字母,这是n^4的复杂度,然后再加上链表,枚举次数不超过43=(35+7),而提取个数因为我们的预处理,变成辣O1啊,所以这样的话总共的复杂度是在n^5的!

掉了一个n啊!这不就能过了吗!

orz出题人。

单词表:

A
AA
AAA
AAAA
ABBE
ABED
ABET
ABLE
ABLY
ABUT
ACE
ACES
ACHE
ACID
ACME
ACNE
ACRE
ACT
AD
ADD
ADDS
ADO
ADS
AFAR
AFT
AGAR
AGE
AGED
AGER
AGES
AGO
AGOG
AGUE
AH
AID
AIDE
AIDS
AIL
AIM
AIMS
AIR
AIRS
AIRY
AJAR
AKIN
ALAS
ALBA
ALE
ALEE
ALGA
ALL
ALLY
ALMA
ALMS
ALOE
ALSO
ALUM
AM
AMEN
AMID
AMMO
AMOK
AMYL
AN
ANAL
AND
ANEW
ANON
ANT
ANTE
ANTI
ANTS
ANUS
ANY
APE
APED
APES
APEX
APSE
APT
AQUA
ARC
ARCH
ARCS
ARE
AREA
ARID
ARK
ARM
ARMS
ARMY
ART
ARTS
AS
ASH
ASK
ASKS
ASP
ASS
AT
ATE
ATOM
ATOP
AUNT
AURA
AUT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E
CELL
CENT
CHAP
CHAR
CHAT
CHEF
CHEW
CHIC
CHIN
CHIP
CHIT
CHOP
CHUM
CITE
CITY
CLAD
CLAM
CLAN
CLAP
CLAW
CLAY
CLIP
CLOD
CLOG
CLOT
CLUB
CLUE
COAL
COAT
COAX
COCA
COCK
COCO
COD
CODE
COED
COG
COGS
COIL
COIN
COKE
COLD
COLT
COMB
COME
CON
CONE
COO
COOK
COOL
COON
COOP
COP
COPE
COPS
COPY
CORD
CORE
CORK
CORN
COST
COSY
COT
COTS
COVE
COW
COWL
COWS
COZY
CRAB
CRAG
CRAM
CREW
CRIB
CROP
CROW
CRUD
CRUX
CRY
CUB
CUBE
CUBS
CUE
CUED
CUES
CUFF
CULL
CULT
CUP
CUPS
CURB
CURD
CURE
CURL
CURS
CURT
CUSP
CUT
CUTE
CUTS
CYST
CZAR
DAD
DADS
DALE
DAM
DAME
DAMN
DAMP
DAMS
DARE
DARK
DARN
DART
DASH
DATA
DATE
DAWN
DAY
DAYS
DAZE
DEAD
DEAF
DEAL
DEAN
DEAR
DEBT
DECK
DEED
DEEM
DEEP
DEER
DEFY
DELL
DEMO
DEN
DENS
DENT
DENY
DESK
DEUS
DEW
DEWY
DIAL
DICE
DID
DIE
DIED
DIEM
DIES
DIET
DIG
DIGS
DIKE
DILL
DIM
DIME
DIMS
DIN
DINE
DING
DINT
DIP
DIPS
DIRE
DIRT
DISC
DISH
DISK
DIVE
DO
DOCK
DOE
DOER
DOES
DOG
DOGS
DOLE
DOLL
DOME
DON
DONE
DONS
DOOM
DOOR
DOPE
DOSE
DOT
DOTE
DOTS
DOVE
DOWN
DOZE
DRAB
DRAG
DRAM
DRAW
DREW
DRIP
DROP
DRUG
DRUM
DRY
DUAL
DUB
DUBS
DUCK
DUCT
DUD
DUE
DUEL
DUES
DUET
DUG
DUKE
DULL
DULY
DUMB
DUMP
DUNE
DUNG
DUNK
DUPE
DUSK
DUST
DUTY
DYAD
DYE
DYED
DYER
DYES
DYNE
EACH
EAR
EAR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AWS
JAY
JAZZ
JEAN
JEEP
JEER
JERK
JEST
JET
JETS
JIG
JIGS
JOB
JOBS
JOG
JOGS
JOIN
JOKE
JOLT
JOT
JOTS
JOY
JOYS
JUDO
JUG
JUGS
JUMP
JUNK
JURE
JURY
JUST
JUT
KEEL
KEEN
KEEP
KEN
KEPT
KERN
KEY
KEYS
KICK
KID
KIDS
KILL
KIN
KIND
KING
KINK
KISS
KIT
KITE
KITS
KNEE
KNEW
KNIT
KNOB
KNOT
KNOW
KUDO
LAB
LABS
LACE
LACK
LACY
LAD
LADS
LADY
LAG
LAGS
LAID
LAIN
LAIR
LAKE
LAMB
LAME
LAMP
LAND
LANE
LAP
LAPS
LARD
LARK
LASH
LASS
LAST
LATE
LAVA
LAW
LAWN
LAWS
LAX
LAY
LAYS
LAZY
LEAD
LEAF
LEAK
LEAN
LEAP
LED
LEE
LEEK
LEER
LEES
LEFT
LEG
LEGS
LEND
LENS
LENT
LESS
LEST
LET
LETS
LEVY
LEWD
LIAR
LICE
LICK
LID
LIDS
LIE
LIED
LIEN
LIES
LIEU
LIFE
LIFT
LIKE
LILY
LIMB
LIME
LIMP
LINE
LINK
LINT
LION
LIP
LIPS
LISP
LIST
LIT
LIVE
LOAD
LOAF
LOAN
LOBE
LOCI
LOCK
LOFT
LOGO
LOGS
LOIN
LONE
LONG
LOOK
LOOM
LOON
LOOP
LOOT
LORD
LORE
LOSE
LOSS
LOST
LOT
LOTS
LOUD
LOUT
LOVE
LOW
LOWS
LUCK
LULL
LUMP
LUNG
LURE
LURK
LUSH
LUST
LUTE
LYNX
LYRE
MACE
MAD
MADE
MAID
MAIL
MAIM
MAIN
MAKE
MALE
MALL
MALT
MAMA
MAN
MANE
MANY
MAP
MAPS
MARE
MARK
MART
MASH
MASK
MASS
MAST
MAT
MATE
MATH
MATS
MAUL
MAZE
ME
MEAD
MEAL
MEAN
MEAT
MEEK
MEET
MELT
MEMO
MEN
MEND
MENS
MENU
MERE
MESH
MESS
MET
META
METE
METS
ME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
PEST
PET
PETS
PEW
PEWS
PHI
PI
PICA
PICK
PIE
PIER
PIES
PIG
PIGS
PIKE
PILE
PILL
PIMP
PIN
PINE
PING
PINK
PINS
PINT
PION
PIP
PIPE
PISS
PIT
PITH
PITS
PITY
PLAN
PLAY
PLEA
PLOD
PLOT
PLOW
PLOY
PLUG
PLUM
PLUS
PLY
POD
PODS
POEM
POET
POGO
POKE
POLE
POLL
POLO
POMP
POND
PONG
PONY
POOL
POOR
POP
POPS
PORE
PORK
PORT
POSE
POSH
POST
POT
POTS
POUR
POUT
POX
PRAY
PREP
PREY
PRIM
PRO
PROD
PROP
PROS
PROW
PRY
PUB
PUBS
PUFF
PUKE
PULL
PULP
PUMA
PUMP
PUN
PUNS
PUNT
PUNY
PUP
PUPA
PUPS
PURE
PURR
PUS
PUSH
PUSS
PUT
PUTS
PUTT
PYRE
QUA
QUAD
QUAY
QUIP
QUIT
QUIZ
QUO
RACE
RACK
RAFT
RAG
RAGE
RAGS
RAID
RAIL
RAIN
RAKE
RAM
RAMP
RAMS
RAN
RANG
RANK
RANT
RAP
RAPE
RAPS
RAPT
RARE
RASH
RASP
RAT
RATE
RATS
RAVE
RAW
RAY
RAYS
RAZE
RE
READ
REAL
REAM
REAP
REAR
RED
REDO
REDS
REED
REEF
REEL
REIN
RELY
REND
RENT
REST
RHO
RIB
RIBS
RICE
RICH
RID
RIDE
RIDS
RIFT
RIG
RIGS
RILL
RIM
RIME
RIMS
RIND
RING
RINK
RIOT
RIP
RIPE
RIPS
RISE
RISK
RITE
ROAD
ROAM
ROAR
ROB
ROBE
ROBS
ROCK
ROD
RODE
RODS
ROE
ROLE
ROLL
ROMP
ROOF
ROOK
ROOM
ROOT
ROPE
ROSY
ROT
ROTS
ROUT
ROVE
ROW
ROWS
RUB
RUBS
RUBY
RUDE
RUE
RUG
RUGS
RUIN
RULE
RUM
RUMP
RUN
RUNG
RUNS
RUNT
RUSH
RUST
RUT
RUTS
RYE
SACK
SAD
SAFE
SAG
SAGA
S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
TANG
TANK
TAP
TAPE
TAPS
TAR
TART
TASK
TAU
TAUT
TAX
TAXI
TEA
TEAM
TEAR
TEAS
TEEM
TEEN
TELL
TEN
TEND
TENS
TENT
TERM
TEST
TEXT
THAN
THAT
THAW
THE
THEM
THEN
THEY
THIN
THIS
THUD
THUG
THUS
TICK
TIDE
TIDY
TIE
TIED
TIER
TIES
TILE
TILL
TILT
TIME
TIN
TINS
TINT
TINY
TIP
TIPS
TIRE
TIT
TITS
TO
TOAD
TOE
TOES
TOIL
TOLD
TOLL
TOMB
TON
TONE
TONS
TOO
TOOK
TOOL
TOP
TOPS
TORE
TORN
TOSS
TOUR
TOW
TOWN
TOY
TOYS
TRAP
TRAY
TREE
TREK
TRIM
TRIO
TRIP
TROD
TROT
TRUE
TRY
TUB
TUBE
TUBS
TUCK
TUFT
TUG
TUGS
TUNE
TURF
TURN
TWAS
TWIG
TWIN
TWO
TWOS
TYPE
TYPO
UGH
UGLY
UNDO
UNIT
UNTO
UP
UPON
URGE
URN
URNS
US
USE
USED
USER
USES
VAIN
VALE
VAN
VANE
VANS
VARY
VASE
VAST
VAT
VATS
VEAL
VEER
VEIL
VEIN
VENT
VERB
VERY
VEST
VETO
VEX
VIA
VIAL
VICE
VIE
VIED
VIER
VIES
VIEW
VILE
VINE
VISA
VITA
VOID
VOLT
VOTE
VOW
VOWS
WADE
WAFT
WAG
WAGE
WAGS
WAIL
WAIT
WAKE
WALK
WALL
WAN
WAND
WANE
WANT
WAR
WARD
WARE
WARM
WARN
WARP
WARS
WART
WARY
WAS
WASH
WASP
WAVE
WAX
WAXY
WAY
WAYS
WE
WEAK
WEAN
WEAR
WEB
WEBS
WEDS
WEE
WEED
WEEK
WEEP
WELD
WELL
WENT
WEPT
WERE
WEST
WET
WETS
WHAT
WHEN
WHIM
WHIP
WHIT
WHIZ
WHO
WHOM
WHY
WICK
WIDE
WIFE
WIG
WIGS
WILD
WILE
WILL
WILT
WILY
WIN
WIND
WINE
WING
WINK
WINS
WIPE
WIRE
WIRY
WISE
WISH
WISP
WIT
WITH
WITS
WOE
WOKE
WOLF
WOMB
WON
WONT
WOO
WOOD
WOOF
WOOL
WOOS
WORD
WORE
WORK
WORM
WORN
WOVE
WRAP
WREN
WRIT
YANK
YARD
YARN
YAWN
YEA
YEAR
YEAS
YELL
YELP
YES
YET
YOKE
YON
YOU
YOUR
ZEAL
ZERO
ZEST
ZINC
ZONE
ZOO
ZOOM
ZOOS

代码:(因单词表在上方给出,所以此处略)

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 35
using namespace std;
string d[2265];
int map[N][N];
int sum1[N][N][N];
int sum2[N][N][N][N];
int fuck[N][N][N][N];
int head[N][N];
int head2[N][N];
int v[N];
int v1[N][N];
int cnt,cnt2;
int n,m;
struct node
{
    int fromx,fromy,x,y,next;
}edge[2265],edge2[2265];
void init()
{
    memset(head,-1,sizeof(head));
    memset(head2,-1,sizeof(head2));
    cnt=1,cnt2=1;
}
void edgeadd(int fromx,int fromy,int to)
{
    edge[cnt].fromx=fromx,edge[cnt].fromy=fromy;
    edge[cnt].x=to;
    edge[cnt].next=head[fromx][fromy];
    head[fromx][fromy]=cnt++;
}
void edgeadd2(int fromx,int fromy,int to,int to2)
{
    edge2[cnt2].fromx=fromx,edge2[cnt2].fromy=fromy;
    edge2[cnt2].x=to,edge2[cnt2].y=to2;
    edge2[cnt2].next=head2[fromx][fromy];
    head2[fromx][fromy]=cnt2++;
}
char s[N];
int main()
{
    //此处放单词表,多背单词少刷水!!!!!!!!!!!!!!!!
    init();
    for(int i=0;i<=2264;i++)
    {
        int len=d[i].size();
        switch(len)
        {
            case 1:v[d[i][0]-'A']=1;break;
            case 2:v1[d[i][0]-'A'][d[i][1]-'A']=1;break;
            case 3:edgeadd(d[i][0]-'A',d[i][1]-'A',d[i][2]-'A');break;
            case 4:edgeadd2(d[i][0]-'A',d[i][1]-'A',d[i][2]-'A',d[i][3]-'A');break;
        }
    }
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        for(int j=1;j<=m;j++)
        {
            map[i][j]=s[j]-'A';
        }
    }
    for(int i=0;i<26;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=m;k>=1;k--)
            {
                sum1[i][j][k]=sum1[i][j-1][k]+sum1[i][j][k+1]-sum1[i][j-1][k+1]+(map[j][k]==i);
                fuck[map[j][k]][i][j][k]=sum1[i][j][k]-(map[j][k]==i);
            }
        }
    }
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<26;j++)
        {
            for(int k=1;k<=n;k++)
            {
                for(int l=m;l>=1;l--)
                {
                    sum2[i][j][k][l]=sum2[i][j][k-1][l]+sum2[i][j][k][l+1]-sum2[i][j][k-1][l+1]+fuck[i][j][k][l];
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(v[map[i][j]])ans++;
            for(int x=i;x>=1;x--)
            {
                for(int y=j;y<=m;y++)
                {
                    if(x==i&&y==j)continue;
                    if(v1[map[i][j]][map[x][y]])ans++;
                    for(int k=head[map[i][j]][map[x][y]];k!=-1;k=edge[k].next)
                    {
                        int to=edge[k].x;
                        ans+=sum1[to][x][y]-(map[x][y]==to);
                    }
                    for(int k=head2[map[i][j]][map[x][y]];k!=-1;k=edge2[k].next)
                    {
                        int to=edge2[k].x;
                        int to2=edge2[k].y;
                        ans+=sum2[to][to2][x][y]-fuck[to][to2][x][y];
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
}
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

打赏
文章很值,打赏犒劳作者一下
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页

打赏

wzq_QwQ

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者